如何将列表转换为DataFrame?

时间:2015-12-03 10:24:16

标签: python list pandas dataframe

我的列表有51列。这是一个小提取物:

[   airportResources.baggage_x  airportResources.arrivalTerminal_x  \
0                         NaN                                   1   

  schedule.serviceClasses_y status_y operationalTimes.actualDateTime_y  
0                       RJY        L                            421075  

[1 rows x 51 columns],    airportResources.baggage_x  airportResources.arrivalTerminal_x  \
0                         NaN                                   1   

  schedule.serviceClasses_y status_y operationalTimes.actualDateTime_y  
0                         Y        L                            421185  

[1 rows x 51 columns],   airportResources.baggage_x  airportResources.arrivalTerminal_x  \
0                         14                                   1   

  schedule.serviceClasses_y status_y operationalTimes.actualDateTime_y  
0                      RFJY        L                            424447  

[1 rows x 51 columns]] 

然后我尝试将此列表转换为DataFrame,如下所示:

data = np.concatenate ([z[51:] for z in flights]) 
data = data.reshape(-1, 51)
flights = pd.DataFrame(data, columns=flights[0][:51])

然后会出现以下错误消息:

ValueError: Shape of passed values is (51, 0), indices imply (1, 0)

问题出现在这行代码中:

flights = pd.DataFrame(data, columns=flights[0][:51])

0 个答案:

没有答案