Pandas Dataframe Add New Column Based On Calulation On Other Column And Avoid Chained Index
I have a pandas dataframe and I need to add a new column, which would be based on calculation of specific columns,indicated by a column 'site'. I have found a way to do this with r
Solution 1:
Well, i´m not too sure about your first quest but i think that this will help you.
import pandas as pd
reader = pd.read_csv(path,engine='python')
reader['new'] = reader['treasury.maturity.rate']+reader['bond.yield']
reader.to_csv('test.csv',index=False)
As you can see,you don´t need get the values before operate with them only reference the column where they are; and to do the same for only a specific row you could filter the dataframe before create the new column.
Post a Comment for "Pandas Dataframe Add New Column Based On Calulation On Other Column And Avoid Chained Index"