这是我试图运行以从我的目录中读取多个 JSON 文件的代码。<file_names> 包含我尝试读取的所有文件的名称。
for file in range(1, len(file_names)):
data = pd.read_json(file_names[number])
df = df.append(data, ignore_index=True)
我收到以下错误:
ValueError:如果使用所有标量值,则必须传递索引
看起来你没有定义数字。您也可以通过等待最后连接 dfs 来加快速度。
假设 file_names 是 list 并且 pd.read_json() 按预期工作,请尝试此操作。
df_hold_list = [] # appending dataframe on each loop is a lot of overhead, so collect them first
for file in file_names:
df_hold_list.append(pd.read_json(file))
df = pd.concat(df_hold_list, axis=0) # check the axis, either 1 or 0 depending on how you want it to look
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句