Issue
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"])
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
Answered By - rhug123
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.