Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 关于熊猫中的concat:使用行数据创建新列_Python_Pandas - Fatal编程技术网

Python 关于熊猫中的concat:使用行数据创建新列

Python 关于熊猫中的concat:使用行数据创建新列,python,pandas,Python,Pandas,同样的问题也发布在pydata谷歌集团上 我想做一个自定义concat,即使用groupby对象中的行 创建新的COL 下面是一个人为的例子: Input data frame name age foo 12 bar 14 df = pandas.DataFrame({ 'name':['foo','bar'],'age': [12,14] }) expected output, a pandas data frame with four cols foo 12 ba

同样的问题也发布在pydata谷歌集团上

我想做一个自定义concat,即使用groupby对象中的行 创建新的COL

下面是一个人为的例子:

Input data frame
name age
foo     12
bar     14

df = pandas.DataFrame({  'name':['foo','bar'],'age': [12,14] })



expected output, a pandas data frame with four cols 
foo 12 bar 14
PS:我正在寻找一个有效的解决方案,因为这将适用于 包含800k奇数分组的分组对象

样本800k数据将具有以下结构。我仍在使用类比,因为实际数据是科学的,而列名可能不是直观的

Subject (grouped by col)
          Name     Age        mark1   
          Foo      12         80     
          Bar      14         90 
我们希望从这个按数据分组的数据框中得到以下数据

Subject Foo 12 80 Bar 14 90

您希望重塑数据帧的值,以便:

In [43]: pandas.DataFrame(df[['name', 'age']].values.reshape(1, 4))
Out[43]:
     0   1    2   3
0  foo  12  bar  14

这应该是有效的,因为整形()返回一个视图。积分。

您能详细介绍800k df的外观吗?当然@elyase..现在有详细信息。当您说您想要一个数据帧
Subject Foo 12 80 Bar 14 90
时,您是什么意思?(一行如何成为数据帧?)另请参见谷歌集团pydata上的相同问题: