[{
"name":"game_time",
"type":"int",
"info":"millisecond count since start of game"
},
{
"name":"round",
"type":"int",
"info":"number of the current round when the even takes place or 0 if no round"
}]
我的尝试:
specs:包含args列的数据框,文件示例附在下面
specs['args'].apply(lambda x : x.split('},{')).to_frame()['args'].apply(pd.Series).apply(lambda x : x.str[2:])
specs['args'].apply(pd.Series)
答案 0 :(得分:1)
在这种情况下,我希望ast能为您提供帮助。
0000:00:0:00:00
这是您想要的结果吗?
如果您希望获得与代码中相同的输出,请参见以下示例
import pandas as pd
from ast import literal_eval
df = pd.read_csv('test_.csv', header = None)
df
Out[1]:
0
0 [{"name":"game_time","type":"int","info":"mill...
1 [{"name":"game_time","type":"int","info":"mill...
2 [{"name":"game_time","type":"int","info":"mill...
3 [{"name":"game_time","type":"int","info":"mill..
lst = [m for s in df[0] for m in literal_eval(s)]
lst
Out[2]:
[{'name': 'game_time',
'type': 'int',
'info': 'millisecond count since start of game'},
{'name': 'round',
'type': 'int',
'info': 'number of the current round when the event takes place or 0 if no round'},
{'name': 'level',
'type': 'int',
'info': 'number of the current level when the event takes place or 0 if no level'},
{'name': 'description',.......
pd.DataFrame.from_dict(lst)
Out[3]:
info name type
0 millisecond count since start of game game_time int
1 number of the current round when the event tak... round int
2 number of the current level when the event tak... level int
3 the text or description of the instruction description string
........
答案 1 :(得分:0)
只需使用数据框构造函数
RotationCorrectionRight(FPT);
RotationCorrectionRight(BPT);
RotationCorrectionLeft(FDT);
RotationCorrectionLeft(BDT);
退出:
data = [{
"name":"game_time",
"type":"int",
"info":"millisecond count since start of game"
},
{
"name":"round",
"type":"int",
"info":"number of the current round when the even takes place or 0 if no round"
}]
print(pd.DataFrame(data))