python - about concat in pandas : using row data to create new columns -
the same question has been posted on pydata google group.
i want custom concat i.e using rows in group object create new cols.
here contrived example:
input data frame name age foo 12 bar 14 df = pandas.dataframe({ 'name':['foo','bar'],'age': [12,14] }) expected output, pandas data frame 4 cols foo 12 bar 14
ps: looking efficient solution applied grouped pandas object containing 800k odd groupings.
sample 800k data have following structure. still using analogy actual data scientific , column names might not intuitive
subject (grouped col) name age mark1 foo 12 80 bar 14 90
what want grouped data following data frame
subject foo 12 80 bar 14 90
you want reshape values of dataframe so:
in [43]: pandas.dataframe(df[['name', 'age']].values.reshape(1, 4)) out[43]: 0 1 2 3 0 foo 12 bar 14
this should efficient reshape() returns view. credits @wouter overmeire.
Comments
Post a Comment