File size: 771 Bytes
51d726d 2872dd0 51d726d 0fd8596 51d726d 0fd8596 51d726d 2872dd0 51d726d 2872dd0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# pandas: For data manipulation and transformation.
# pyarrow: For reading and writing Parquet files.
import pyarrow.parquet as pq
import os
import json
table = pq.read_table('data/test-00000-of-00001.parquet')
df = table.to_pandas() # DataFrame
print("INICIO", df)
with open("images/images.json") as json_file:
data = json.load(json_file)
image_rows = data["imagesToUpload"]
for img in image_rows:
image_path = f"images/{img["name"]}"
image_text = img["text"]
with open(image_path, "rb") as image:
image_bytes = image.read()
new_row = {'image': {'bytes': image_bytes, 'path': image_path}, 'text': image_text}
df = df._append(new_row, ignore_index=True)
os.remove(image_path)
print("FIN", df)
df.to_parquet('data/test-00000-of-00001.parquet') |