我的解决方案
>>> i = 2
>>> list1 = []
>>> list1.append(i)
>>> list1
[2]
Run Code Online (Sandbox Code Playgroud)
有更优雅的解决方案吗?
我正在使用以下内容从文件data.json中读取一条JSON行:
[
{
"timestamp": 1436266865,
"rates": {
"EUR": 0.911228,
"JPY": 122.5463,
"AUD": 1.346118
}
},
{
"timestamp": 1436277661,
"rates": {
"JPY": 122.4789,
"AUD": 1.348871,
"EUR": 0.91433
}
}
]
Run Code Online (Sandbox Code Playgroud)
进入熊猫DataFrame.我想使用"timestamp"作为DataFrame的索引.我实现了这个目标:
df = pandas.read_json('data.json')
df.index = df['timestamp']
df.drop('timestamp', axis=1, inplace=1)
Run Code Online (Sandbox Code Playgroud)
是否可以在一行中完成?