Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Pandas Copy Columns

How do I copy multiple columns from one dataframe to a new dataframe? it would also be nice to rename them at the same time

df2['colA']=df1['col-a']  #This works

df2['colA', 'colB']=df1['col-a', 'col-b'] #Tried and Failed

Thanks

like image 599
RMichalowski Avatar asked May 16 '17 19:05

RMichalowski


1 Answers

You have to use double brackets:

df2[['colA', 'colB']] = df1[['col-a', 'col-b']]
like image 103
Andy Hayden Avatar answered Sep 22 '22 02:09

Andy Hayden