【发布时间】:2020-12-16 07:14:36
【问题描述】:
我已使用以下代码将图像转换为 csv:
import pandas as pd
from PIL import Image
import numpy as np
image_array = []
for name in combined_df['path']:
image_array.append(np.array(Image.open(name)))
image_df_1 = pd.DataFrame(image_array) #Then coverted list to dataframe
image_df_1.to_csv('image.csv', index=False) # exported it to csv (question 1)
csv_df = pd.read_csv('image.csv') # exported csv using pandas (question 2)
# I want to see images from csv file but there is problem
np.array(csv_df.iloc[0][0]).shape # (question 3)
Output: ()
# but if I see shape of dataframe before saving it to csv
np.array(image_df_1.iloc[0][0]).shape
output: (466, 806, 3)
有什么我做错了吗:
- 将数据帧保存到 csv 文件时?
- 还是在读取 csv 文件时?
- 还是在将值转换为数组时?
# data is available but not able to convert in from of array
csv_df.iloc[0][0]
Output: '[[[180 193 212]\n [181 194 213]\n [182 195 214]\n ...\n [177 190 209]\n [177 190 209]\n [177 190 209]]\n\n [[180 193 212]\n [181 194 213]\n
请指教。
【问题讨论】:
-
不能使用
image_df_1.to_json('image.csv', index=False)将其保存为json文件吗?
标签: python pandas numpy csv python-imaging-library