我试图从JSON文件创建DataFrames。
我有一个名为“ Series_participants”的列表,其中包含此JSON文件的一部分。当我打印它时,我的列表看起来像这样。
participantId 1
championId 76
stats {'item0': 3265, 'item2': 3143, 'totalUnitsHeal...
teamId 100
timeline {'participantId': 1, 'csDiffPerMinDeltas': {'1...
spell1Id 4
spell2Id 12
highestAchievedSeasonTier SILVER
dtype: object
<class 'list'>
在我尝试将此列表转换为这样的DataFrame之后
pd.DataFrame(Series_participants)
但是,熊猫使用“统计”和“时间轴”的值作为DataFrame的索引。我希望具有自动索引范围(0,...,n)
编辑1:
participantId championId stats teamId timeline spell1Id spell2Id highestAchievedSeasonTier
0 1 76 3265 100 NaN 4 12 SILVER
我想要一个数据框,其中包含“统计”和“时间轴”列,这些列包含其值的系列,如“系列”显示中一样。
我的错误是什么?
编辑2:
我试图手动创建DataFrame,但是熊猫没有考虑我的选择,最后选择了Series的“ stats”键的索引。
这是我的代码:
for j in range(0,len(df.participants[0])):
for i in range(0,len(df.participants[0][0])):
Series_participants = pd.Series(df.participants[0][i])
test = {'participantId':Series_participants.values[0],'championId':Series_participants.values[1],'stats':Series_participants.values[2],'teamId':Series_participants.values[3],'timeline':Series_participants.values[4],'spell1Id':Series_participants.values[5],'spell2Id':Series_participants.values[6],'highestAchievedSeasonTier':Series_participants.values[7]}
if j == 0:
df_participants = pd.DataFrame(test)
else:
df_participants.append(test, ignore_index=True)
双循环是解析JSON文件的所有“参与者”。
心有法竹
四季花海
手掌心
随时随地看视频慕课网APP
相关分类