小编lat*_*arf的帖子

如何在python中将单个数字转换为单个项目列表

我的解决方案

>>> i = 2
>>> list1 = []
>>> list1.append(i)
>>> list1
[2]
Run Code Online (Sandbox Code Playgroud)

有更优雅的解决方案吗?

python integer list

13
推荐指数
2
解决办法
3万
查看次数

来自read_json()的pandas数据帧的时间戳索引

我正在使用以下内容从文件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)

是否可以在一行中完成?

python json timestamp pandas

3
推荐指数
1
解决办法
1713
查看次数

标签 统计

python ×2

integer ×1

json ×1

list ×1

pandas ×1

timestamp ×1