[Tutor] Adding a new row to the dataframe with datetime as index

Asif Iqbal vadud3 at gmail.com
Sun May 20 23:01:33 EDT 2018


I am trying to add a new row to a new date in the dataframe like below

   df.loc['2018-01-24'] = [0,1,2,3,4,5]

And I am getting the following error

  ValueError: cannot set using a list-like indexer with a different length
than the value

I do have the right number of columns and I can lookup a row by the date


  (8034, 6)

  DatetimeIndex(['2018-01-23', '2018-01-22', '2018-01-19', '2018-01-18',
               '2018-01-17', '2018-01-16', '2018-01-12', '2018-01-11',
               '2018-01-10', '2018-01-09',
               '1986-03-25', '1986-03-24', '1986-03-21', '1986-03-20',
               '1986-03-19', '1986-03-18', '1986-03-17', '1986-03-14',
               '1986-03-13', '2018-01-24'],
              dtype='datetime64[ns]', name='date', length=8034, freq=None)

Any idea how to add a new row to a new date?

Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

More information about the Tutor mailing list