Issue
Currently I have this data set:
data={'a1':[1,2,3,4,5],'a2':[4,5,6,7,8],'b1':[2,5,3,7,9],'b2':[7,5,8,9,3],'c1':[2,4,5,7,5]}
df=pd.DataFrame(data)
df
How can i script python if I would like to add main column headers to the existing column headings. For instance, 'a1' & 'a2 will be categorized under 'A', 'be' & 'b2' will be categorized under 'B' and 'c1' remains alone. For example:
Thank you in advance :)
Solution
data={'a1':[1,2,3,4,5],'a2':[4,5,6,7,8],'b1':[2,5,3,7,9],'b2':[7,5,8,9,3],'c1':[2,4,5,7,5]}
df=pd.DataFrame(data)
df.columns=[['a','a','b','b','c'],['a1','a2','b1','b2','c1']]
Answered By - student
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.