小编Lon*_*rgy的帖子

字典到数据帧错误:“如果使用所有标量值,则必须传递索引”

目前,我正在使用 for 循环从文件夹中读取 csv 文件。读取 csv 文件后,我将数据存储到字典的一行中。当我使用“print(list_of_dfs.dtypes)”打印数据类型时,我收到:

dtype:对象 DATETIME:对象 值:float64 ID:int64 ID 名称:对象。

请注意,这是一个嵌套字典,其中每个数据字段中存储了数千个值。我有上面列出的 26 行结构。我正在尝试将字典行附加到数据框中,其中只有 1 行由数据字段组成:

索引日期时间值 ID ID 名称。

注意:我正在学习Python。我尝试使用数组来存储数据,然后将数组转换为数据帧,但无法附加数据帧的行。

使用字典方法我尝试“df = pd.Dataframe(list_of_dfs)”这会引发错误。

list_of_dfs = {} 

for I in range(0,len(regionLoadArray)
list_of_dfs[I] = pd.read_csv(regionLoadArray[I]) 

#regionLoadArray contains my- file names from list directory.

dataframe = pd.DataFrame(list_of_dfs)
#this method was suggested at thispoint.com for nested dictionaries.
#This is where my error occurs^
Run Code Online (Sandbox Code Playgroud)

ValueError:如果使用所有标量值,则必须传递索引

感谢您对这个问题的任何帮助,因为我是 python 新手。我当前的目标是简单地生成一个带有标题的数据框,然后将其发送到 csv。

python excel dictionary dataframe pandas

26
推荐指数
4
解决办法
6万
查看次数

标签 统计

dataframe ×1

dictionary ×1

excel ×1

pandas ×1

python ×1