我有一个应该是json的csv,我正在尝试在多个列中对它进行排序
它可能是这样的json(如果有帮助的话):
{"username":"jane.doe@gmail.com"
"app": [
{"appid":"123456"
"appname:"apppname"
"scopes":["scope1","scope2"]}
{"appid":"23456
"appname:"apppname"2
"scopes":["scope1","scope2"]}
{"username":john.doe@gmail.com"
...}
这是数据
它继续下去,用户可以拥有任意数量的应用程序,这些应用程序可以有许多作用域。 预期产量
所以我做了,但我觉得我的代码有点难看,我想知道你是否有更好的想法
for index, row in df.iterrows():
if 'User' in df.at[index,'value']:
x=index
df.at[x,'User']=df.at[index,'value']
elif 'Client ID' in df.at[index,'value']:
df.at[x,'Client_ID']=df.at[index,'value']
x=x+1
elif 'anonymous' in df.at[index,'value']:
df.at[x,'anonymous']=df.at[index,'value']
elif 'displayText' in df.at[index,'value']:
df.at[x,'displayText']=df.at[index,'value']
elif 'nativeApp' in df.at[index,'value']:
df.at[x,'nativeApp']=df.at[index,'value']
elif 'userKey' in df.at[index,'value']:
df.at[x,'userKey']=df.at[index,'value']
elif 'http' in df.at[index,'value']:
df.at[x,'scopes']=df.at[x,'scopes'] + ' ' +df.at[index,'value']
那我就把空行放下。 我想知道是否有更好的方法来做到这一点,所有这些埃利夫不是很干净
任何帮助都将不胜感激
您的文件非常接近于YaML,插入缺少的缩进并列出分隔符,然后使用
json_normalize()
加载非常简单我想你是说你有一个csv文件
如果您可以依赖该结构,即1个用户,1到N个客户机ID节,范围节为1。。N URL您可以执行以下操作:
使用提供的数据打印用户列表:
相关问题 更多 >
编程相关推荐