我遇到list
lists
到pandas
DataFrame的问题。
这是我的数据:
list_of_lists = np.array(hazard)
[['13-06-2016' '2.0' '1.0' '3.0' '88.0' '0.0' '72.0' '7.27']
['18-06-2016' '1.0' '0.0' '3.0' '85.5' '0.0' '77.0' '8.05']
['22-06-2016' '3.0' '0.0' '5.0' '91.5' '0.0' '66.0' '7.54']
['26-06-2016' '3.0' '2.0' '4.0' '89.6' '1.0' '74.0' '10.0']
['01-07-2016' '3.0' '0.0' '1.0' '88.9' '0.0' '72.0' '6.75']
['27-08-2016' '7.0' '4.0' '2.0' '81.8' '2.0' '91.0' '8.79']
['01-09-2016' '0.0' '0.0' '1.0' '59.3' '1.0' '46.0' '6.92']
['11-09-2016' '2.0' '1.0' '4.0' '91.7' '0.0' '71.0' '6.84']
['16-09-2016' '0.0' '0.0' '1.0' '81.8' '1.0' '68.0' '7.07']
['24-09-2016' '2.0' '0.0' '1.0' '84.2' '0.0' '52.0' '6.11']
['30-10-2016' '3.0' '3.0' '5.0' '83.0' '1.0' '72.0' '8.87']
['05-11-2016' '3.0' '3.0' '1.0' '94.6' '0.0' '75.0' '9.76']
['09-11-2016' '1.0' '1.0' '4.0' '92.1' '0.0' '84.0' '7.21']
['20-11-2016' '0.0' '0.0' '5.0' '84.6' '1.0' '92.0' '8.27']
['26-11-2016' '2.0' '1.0' '1.0' '81.8' '0.0' '46.0' '7.19']
['26-12-2016' '5.0' '2.0' '4.0' '85.7' '1.0' '87.0' '10.0']
['31-12-2016' '2.0' '1.0' '5.0' '86.0' '1.0' '65.0' '7.78']
['04-01-2017' '2.0' '0.0' '1.0' '83.6' '1.0' '81.0' '6.07']]
我有一个pandas
数据框,我构建为
player_df = pd.DataFrame(columns=['Date', 'Total Shots', 'On Target',
'Key Passes', 'Passing Accuracy', 'Aerials Won',
'Touches', 'WhoScored Rating'])
现在我尝试player_df.append(list_of_lists)
我明白了,
TypeError:无法连接非NDFrame对象。
有人能告诉我这里出了什么问题吗?列表的长度与这里的列数匹配,所以它肯定应该没问题?
答案 0 :(得分:5)
错误告诉您需要一个pandas NDFrame对象,最常见的是DataFrame。尝试将列表列表转换为数据帧,然后附加
player_df.append(pd.DataFrame(list_of_lists, columns=player_df.columns))