我曾尝试使用dataframe将列和值添加到json文件中,但似乎在我尝试删除一些列之后,它会返回到原始数据文件。我还面临着无法将其保存到csv文件中的问题。所以想知道也许我不能使用dataframe来做这件事?
它就像一个列表,分成不同的列(总共大约30行),但是我想删除一些,比如路由和urls,同时添加三列长度,maxcal,mincal (这三列中的所有值都在路由列中)
到目前为止,我已经做到了这一点,并被卡住了:
import pandas as pd
import json
data = pd.read_json('fitness.json') # fitness.json is the filename of the json file
fitness2 = pd.DataFrame (fitness2)
fitness2
data.join(fitness2, lsuffix="_left") # to join the three columns into the data table
我不确定如何删除route、'MapURL‘、'MapURL_tc’、'MapURL_sc‘的列,然后最终保存为csv,如输出所示。
谢谢。
发布于 2021-09-16 15:21:28
您可以删除列,然后连接两个数据帧:
data.drop(['MapURL', 'MapURL_tc', 'MapURL_sc'], inplace=True, axis=1)
pd.concat([data,fitness2], axis=1) # to join the three columns into the data table
https://stackoverflow.com/questions/69210285
复制相似问题