问题描述
我正在尝试从图像文件(.png 文件)列表中创建一个 Pandas 数据框
I am trying to create a pandas dataframe from a list of image files (.png files)
samples = []
img = misc.imread('a.png')
X = img.reshape(-1, 3)
samples.append(X)
我在这样的示例中添加了多个 .png 文件.然后我试图从中创建一个熊猫数据框.
I added multiple .png files in samples like this. I am then trying to create a pandas dataframe from this.
df = pd.DataFrame(samples)
它抛出错误ValueError:必须通过二维输入".这里有什么问题?是否真的可以将图像文件列表转换为熊猫数据框.我对熊猫完全陌生,所以不要介意这看起来很傻.
例如X = [[1,2,3,4],[2,3,4,5]] df = pd.DataFrame(X)
按预期给了我一个很好的样本 2 数据框(第 2 行第 4 列),但图像文件不会发生这种情况.
It is throwing error "ValueError: Must pass 2-d input". What is wrong here? Is it really possible to convert a list of image files to pandas dataframe. I am totally new to panda, so do not mind if this looks silly.
For ex.X = [[1,2,3,4],[2,3,4,5]] df = pd.DataFrame(X)
gives me a nice dataframe of samples 2 as expected (row 2 column 4), but it is not happening with image files.
推荐答案
你可以使用:
df = pd.DataFrame.from_records(samples)
这篇关于从图像文件列表创建 pandas 数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!