首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python系列组合行

Python系列组合行
EN

Stack Overflow用户
提问于 2016-01-20 10:59:12
回答 1查看 521关注 0票数 0

我的pd.series看起来是这样的:

代码语言:javascript
复制
df.head()
0      status parentName  name      describe parent...
1      status parentName  name      describe parent...
2      status parentName  name      describe parent...
3      status parentName  name      describe parent...
4      status parentName  name      describe parent...
Name: destinationurl, dtype: object

每一行都是一个dataframe,如下所示:

代码语言:javascript
复制
    status  parentName  name    describe    parentDescribe  parentEnName    parentID    id  enName
       0    0   IT  电子邮箱    提供电子邮箱服务的站点。        Information Technology  25  144 Email

现在,我希望使用apply函数组合所有行,然后将其转换为dataframe。就像R中的“rbind”函数一样。

我怎样才能用Python Pandas做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-20 11:03:01

您可以使用pd.concat并在Series上调用tolist

代码语言:javascript
复制
In [144]:
s = pd.Series([pd.DataFrame(data=np.random.randn(5,3), columns=list('abc')), pd.DataFrame(data=np.random.randn(5,3), columns=list('abc')), pd.DataFrame(data=np.random.randn(5,3), columns=list('abc'))])
s

Out[144]:
0              a         b         c
0  0.295349 -1...
1              a         b         c
0 -0.380644  0...
2              a         b         c
0  0.329135  1...
dtype: object

In [149]:
pd.concat(s.tolist(), ignore_index=True)

Out[149]:
           a         b         c
0   0.295349 -1.128448 -0.674335
1   0.413450  0.211495  0.695035
2  -1.983857 -0.795089 -1.807442
3  -0.366494 -1.784717  1.257727
4  -0.651171  1.430601 -0.729049
5  -0.380644  0.986193  0.146934
6  -0.551766 -0.048919  0.315231
7  -0.649579  0.252312 -2.307680
8  -0.715894 -0.134816  0.103490
9  -0.582027 -0.487878  0.836762
10  0.329135  1.266439 -0.071934
11 -0.022002  0.664152 -0.159218
12 -1.411058  0.046058  1.467763
13  0.116095 -2.731663 -0.448027
14 -0.320958  0.587676 -0.654869
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34898159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档