Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add column name from the pd.concat?

I am wondering is there any way to add column name from series of data.

I thought is something like this

std_df = pd.concat([q,w], axis=1, columns= ["apple","banana"])

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But I get an error of concat() got an unexpected keyword argument 'columns'

I’ve tried names instead of columns, still not working.

>Solution :

pd.concat() has the keys parameter that will work for this purpose:

s1 = pd.Series([1,2,3])
s2 = pd.Series([4,5,6])

df = pd.concat([s1,s2],keys = ['A','B'],axis=1)

Output:

   A  B
0  1  4
1  2  5
2  3  6
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading