Home > Net >  Add columns to end of dataframe based on dynamic number of Columns
Add columns to end of dataframe based on dynamic number of Columns

Time:10-28

I have a dataframe where the number of columns shift month over month. I would like to create 3 empty columns at the end of each dataframe.

I use insert but because numbers of columns shift month over month i am left with error

IndexError: index 59 is out of bounds for axis 0 with size 58

my code:

netnewprocess.insert(59, 'date', '')
netnewprocess.insert(60, 'Analyst Review', '')
netnewprocess.insert(61, 'SM Review', '')

CodePudding user response:

If you just add a column like so, it will tack the column on to the right side of your DataFrame, and you don't need to specify an index:

netnewprocess['date'] = ''
netnewprocess['Analyst Review'] = ''
netnewprocess['SM Review'] = ''
  • Related