Issue
I have a dataframe and I want to substract a column from multiple columns code:
df = pd.DataFrame('A':[10,20,30],'B':[100,200,300],'C':[15,10,50])
# Create a new A and B columns by sub-stracting C from A and B
df[['newA','newB']] = df[['A','B']]-df['C']
Present output:
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis
Solution
You can check sub
df[['newA', 'newB']] = df[['A', 'B']].sub(df['C'],axis=0)
df
Out[114]:
A B C newA newB
0 10 100 15 -5 85
1 20 200 10 10 190
2 30 300 50 -20 250
Answered By - BENY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.