Upload devide.py with huggingface_hub
Browse files
devide.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
# 入力となるJSONファイル名
|
| 4 |
+
input_json_file = 'dataset.json'
|
| 5 |
+
|
| 6 |
+
# チャンクサイズ(16分の1に設定)
|
| 7 |
+
chunk_size = 1600240008 // 59
|
| 8 |
+
|
| 9 |
+
def process_data_chunks():
|
| 10 |
+
# JSONファイルを読み込み、指定した行数ごとに分割する
|
| 11 |
+
for chunk in pd.read_json(input_json_file, lines=True, chunksize=chunk_size):
|
| 12 |
+
yield chunk
|
| 13 |
+
|
| 14 |
+
# ジェネレータを使ってチャンクごとにデータを処理する
|
| 15 |
+
for chunk_count, data_chunk in enumerate(process_data_chunks(), start=1):
|
| 16 |
+
output_file = f'output{chunk_count}.json'
|
| 17 |
+
data_chunk.to_json(output_file, orient='records', lines=True)
|