我不断收到“列的长度必须与键相同”的错误。不知道为什么
这是我更改熊猫数据框时的代码...
sdf = pd.DataFrame(list(shots.items()),columns = ['Coordinates', 'Occurences (S, G)'])
#sdf['Percentage']=sdf['Occurences (S, G)'].apply( lambda x: x[1]/x[0])
sdf[['S','G']] = pd.DataFrame(sdf['Occurences (S, G)'].tolist(), index=sdf.index)
sdf[['X-','Y']] = pd.DataFrame(sdf['Coordinates'].tolist(), index=sdf.index)
sdf['Shot Percentage'] = sdf['G'] / sdf['S']
sdf = sdf.drop(['Coordinates', 'Occurences (S, G)'], axis = 1)
sdf['X'] = abs(sdf['X-'])
sdf = sdf.drop(['X-'], axis = 1)
sdf = sdf[["X", "Y", "S", "G", "Shot Percentage"]]
这是我正在搜索的数据的示例。...
}, {
"players" : [ {
"player" : {
"id" : 8476948,
"fullName" : "Charles Hudon",
"link" : "/api/v1/people/8476948"
},
"playerType" : "Shooter"
}, {
"player" : {
"id" : 8475883,
"fullName" : "Frederik Andersen",
"link" : "/api/v1/people/8475883"
},
"playerType" : "Goalie"
} ],
"result" : {
"event" : "Shot",
"eventCode" : "TOR206",
"eventTypeId" : "SHOT",
"description" : "Charles Hudon Wrap-around saved by Frederik Andersen",
"secondaryType" : "Wrap-around"
},
"about" : {
"eventIdx" : 76,
"eventId" : 206,
"period" : 1,
"periodType" : "REGULAR",
"ordinalNum" : "1st",
"periodTime" : "14:43",
"periodTimeRemaining" : "05:17",
"dateTime" : "2018-10-03T23:42:53Z",
"goals" : {
"away" : 1,
"home" : 1
}
让我知道您是否知道解决方法 谢谢!