1.

How to add new column to pandas dataframe?

Answer»

A new COLUMN can be added to a pandas DATAFRAME as follows:

import pandas as pd data_info = {'first' : pd.Series([1, 2, 3], index=['a', 'b', 'C']), 'second' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])} df = pd.DataFrame(data_info) #To ADD new column thirddf['third']=pd.Series([10,20,30],index=['a','b','c']) print (df) #To add new column fourthdf['fourth']=df['first']+info['third'] print (df)


Discussion

No Comment Found