从for循环中将序列附加到dict或list或dataframe吗? [英] Append series to dict or list or dataframe from for loop?

查看:88
本文介绍了从for循环中将序列附加到dict或list或dataframe吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个for循环,给出了这样的内容:

I have created a for loop which gives an out like this:

       SSTIME
SCODE        
0           0
1          57
3         202

我在本系列中做了reset_index我得到了这个:

I did reset_index on this series and i got this:

   SCODE  SSTIME
0      0       0
1      1      57
2      3     202

我想将每个结果附加到一个具有scode和sstime列的数据帧中。

I want to append each result into a dataframe which will have column of scode and sstime.

PS:SCODE的长度可以不同。

P.S: SCODE can be of different length.

我的目标是从结果中创建一个数据框。

My objective is to create a Dataframe from that results.

任何帮助将不胜感激。

推荐答案

我认为您不需要reset_index ,但 concat 系列列表中的c>

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)

这篇关于从for循环中将序列附加到dict或list或dataframe吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆