问题
I have created a for loop which gives an out like this:
SSTIME
SCODE
0 0
1 57
3 202
I did reset_index on this series and i got this:
SCODE SSTIME
0 0 0
1 1 57
2 3 202
I want to append each result into a dataframe which will have column of scode and sstime.
P.S: SCODE can be of different length.
My objective is to create a Dataframe from that results.
Any help would be appreciated.
回答1:
I think you need not reset_index, but concat of list of Series
:
list_ser = []
#sample loop for crate Series
for x in L:
s = create_function()
list_ser.append(s)
df = pd.concat(list_ser)
回答2:
You can convert each of these dataframes to a dictionary with pandas.DataFrame.to_dict()
And afterwards add to a list:
result = []
for x in range(1,13):
result.append(x)
来源:https://stackoverflow.com/questions/45461346/append-series-to-dict-or-list-or-dataframe-from-for-loop