2013-10-26 146 views
1

我有兩個數據幀 我的第一數據幀,start_df_1,看起來像這樣:的Python:添加一列到大熊貓數據幀

start_df_1 

       0 
0 3Degrees_Inc 
1 3Degrees_Inc 
2 3Degrees_Inc 
3 3Degrees_Inc 
4 3Degrees_Inc 
5 3Degrees_Inc 
6 3Degrees_Inc 
7 3Degrees_Inc 
8 3Degrees_Inc 
9 3Degrees_Inc 
10 3Degrees_Inc 

我的第二數據幀friends_df看起來像這樣:

friends_df 
      0 
0  MEGreenPower 
1  LympheDIVAs 
2  Ecopreneurist 
3  issielapowsky 
4  NatureClimate 
5  miketuritzin 
6   greenbang 
7  GoodCleanTech 
8   EDFbiz 
9   adavies47 
10  petedanko 

我試圖建立一個新的數據幀,這樣的:

concatenated_df   

       User  Follower 
0  MEGreenPower 3Degrees_Inc 
1  LympheDIVAs 3Degrees_Inc 
2  Ecopreneurist 3Degrees_Inc 
3  issielapowsky 3Degrees_Inc 
4  NatureClimate 3Degrees_Inc 
5  miketuritzin 3Degrees_Inc 
6   greenbang 3Degrees_Inc 
7  GoodCleanTech 3Degrees_Inc 
8   EDFbiz 3Degrees_Inc 
9   adavies47 3Degrees_Inc 
10  petedanko1 3Degrees_Inc 

注意新列被添加,並且第一列和第二列分別被命名爲「用戶」和「追隨者」。 我想:

EDGE_LIST1 = pandas.DataFrame.from_dict({'User':friends_df, 
             'Follower': start_df_1}, orient='columns') 

但是它扔我一個錯誤:

ValueError: If using all scalar values, you must must pass an index 

請你幫助我嗎?謝謝。

回答

1

我找到了一個解決方案;你只是這樣做:

EDGE_LIST1 = pandas.concat({'User':start_df_1, 'Follower': friends_df}, axis=1)