-2

I have a simple question, I am creating new column in a list of dataFrame within function. I got this error

data['datenum'] = np.zeros((data))

TypeError: 'DataFrame' object cannot be interpreted as an integer
Iffi
  • 1
  • 2
  • https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas – foobar Apr 09 '20 at 02:39

1 Answers1

1

Your argument to np.zeros needs to be an integer. Right now you have data, which you say is a DataFrame. Perhaps you're looking for:

data['datenum'] = np.zeros(data.shape[0])

If you have multiple dataframes, you can do the following:

for data in dataframes: 
    data['datenum'] = np.zeros(data.shape[0])
ananyamous
  • 161
  • 1
  • 9
  • thanks @ananyajoshi I actually have list of dataframes not only single dataframe – Iffi Apr 09 '20 at 03:04
  • Hi @lffi not sure what you mean, if you need any more help do let me know with more details! – ananyamous Apr 09 '20 at 04:12
  • @anayajoshi I actually have list of DataFrames e.g df = [df1,df2,df3....] which I am using in function so I need to create zero column for each dataframe in the list – Iffi Apr 09 '20 at 05:59
  • The above should work now, just replace dataframes with df. Please accept the answer if so. – ananyamous Apr 09 '20 at 07:56