[Solved] TypeError: cannot concatenate a non-NDFrame object

I have this DatetimeIndex:

dates = DatetimeIndex(['2017-06-09', '2017-06-10', '2017-06-11', '2017-06-12',
               '2017-06-13', '2017-06-14'],
              dtype='datetime64[ns]', freq='<DateOffset>')

I want to take dates and append them to my DataFrame df:

for i in xrange(0,5):

I get this error TypeError: cannot concatenate a non-NDFrame object.


sample data of df:

2017-06-05   -0.944868
2017-06-06    0.073623
2017-06-07   -0.687232
Freq: <DateOffset>, dtype: float64

Solution #1:

If length of df is same as DatetimeIndex and need create index:

df.index = dates 

If not try filter by length of index what is same as length of df:

df.index = dates[:len(df.index)]

If need new column:

df['a'] = dates 

If not:

df['a'] = dates[:len(df.index)]

If need use only first 5 values:

df['a'] = dates[:5]


I think you need union for concatenate index to dates and then reindex:

df = df.reindex(df.index.union(dates), fill_value=-0.944868)
print (df)
2017-06-05   -0.944868
2017-06-06    0.073623
2017-06-07   -0.687232
2017-06-09   -0.944868
2017-06-10   -0.944868
2017-06-11   -0.944868
2017-06-12   -0.944868
2017-06-13   -0.944868
2017-06-14   -0.944868
Name: <DateOffset>, dtype: float64
Respondent: user7379562

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy