<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title>chunk 만들기 코드 by 서강식</title>
      <link>https://padlet.com/kangsikseoul/jj7eahe0q6i94iui</link>
      <description></description>
      <language>en-us</language>
      <pubDate>2025-01-09 11:46:05 UTC</pubDate>
      <lastBuildDate>2025-01-09 11:47:44 UTC</lastBuildDate>
      <webMaster>hello@padlet.com</webMaster>
      <image>
         <url></url>
      </image>
      <item>
         <title>chunk 로 읽기</title>
         <author>kangsikseoul</author>
         <link>https://padlet.com/kangsikseoul/jj7eahe0q6i94iui/wish/3285199406</link>
         <description><![CDATA[<p>import numpy as np</p><p>import pandas as pd</p><p>from pathlib import Path</p><p># 파일 경로 설정 (절대 경로)</p><p>data_path = Path(r'C:\Users\user\Desktop\otto-recommender-system')</p><p>train_file_path = data_path / 'train.jsonl'</p><p># 파일 존재 여부 확인</p><p>if not train_file_path.exists():</p><p>    raise FileNotFoundError(f"파일이 존재하지 않습니다: {train_file_path}")</p><p># 전체 라인 수 계산</p><p>num_lines = sum(1 for line in open(train_file_path, 'r', encoding='utf-8'))</p><p>print(f'전체 라인 수: {num_lines:_}')</p><p># 청크 크기와 청크 수 설정</p><p>chunksize = 100_000</p><p>num_chunks = int(np.ceil(num_lines / chunksize))</p><p>print(f'청크 수: {num_chunks:_}')</p><p># 처음 두 청크 읽기 및 병합</p><p>n = 2</p><p>train_sessions = pd.DataFrame()</p><p>chunks = <a rel="noopener noreferrer nofollow" href="http://pd.read">pd.read</a>_json(train_file_path, lines=True, chunksize=chunksize)</p><p>for e, chunk in enumerate(chunks):</p><p>    if e &lt; n:</p><p>        train_sessions = pd.concat([train_sessions, chunk])</p><p>    else:</p><p>        break</p><p># 데이터프레임 설정</p><p>train_sessions = train_sessions.set_index('session', drop=True).sort_index()</p><p># 결과 출력</p><p>print(train_sessions.head())</p><p><br/></p>]]></description>
         <enclosure url="" />
         <pubDate>2025-01-09 11:46:26 UTC</pubDate>
         <guid>https://padlet.com/kangsikseoul/jj7eahe0q6i94iui/wish/3285199406</guid>
      </item>
   </channel>
</rss>
