Python 正在将列表列表追加到pd.Dataframe()中
我在Python 正在将列表列表追加到pd.Dataframe()中,python,pandas,numpy,Python,Pandas,Numpy,我在list到pandasDataFrame的list中遇到问题 以下是我的数据: 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'
list
到pandas
DataFrame的list
中遇到问题
以下是我的数据:
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
dataframe,我已经构建为
player_df = pd.DataFrame(columns=['Date', 'Total Shots', 'On Target',
'Key Passes', 'Passing Accuracy', 'Aerials Won',
'Touches', 'WhoScored Rating'])
现在当我尝试player\u df.append(列表的列表)
我知道
TypeError:无法连接非NDFrame对象
有人能告诉我这里出了什么问题吗?列表的长度与这里的列数相匹配,所以肯定可以吗 错误告诉您需要一个最常见的数据帧对象。尝试将列表列表转换为数据帧,然后追加
player_df.append(pd.DataFrame(list_of_lists, columns=player_df.columns))
一如既往地正确。谢谢重要的是要记住,这不会在适当的位置修改
player_df
,只会返回附加的df。