2017-08-02 115 views
-1

我創建了一個for循環,其給出了這樣的:附加系列從for循環的詞典或列表或數據框?

 SSTIME 
SCODE   
0   0 
1   57 
3   202 

我做reset_index在這個系列,我得到這個:

SCODE SSTIME 
0  0  0 
1  1  57 
2  3  202 

我想每個結果追加到一個數據幀,其將有scode和sstime的列。

P.S:SCODE可以有不同的長度。

我的目標是從該結果創建一個數據框。

任何幫助,將不勝感激。

+0

你有任何的代碼? – citizen2077

回答

1

我覺得你不必reset_index,但list of Seriesconcat

list_ser = [] 
#sample loop for crate Series 
for x in L: 
    s = create_function() 
    list_ser.append(s) 

df = pd.concat(list_ser) 
+0

,我無法在數據框中附加結果。 – Dheeraj

+0

你可以添加一些其他系列的問題嗎?因爲這應該起作用。 – jezrael

+0

這是工作,但列名稱也是每次都追加。 – Dheeraj

0

這些dataframes你可以轉換成字典,pandas.DataFrame.to_dict()

,又重新添加到列表:

result = [] 
for x in range(1,13): 
    result.append(x) 
相關問題