0

I have a dataframe which the first two columns are 'number' and 'date', and some values in 'number' are supposed to be in 'date',e.g.:

                number               date
10    2013-10-29 00:00:00             nan

I want to move 2013-10-29 00:00:00 from df.ix[10]['number'] to df.ix[10]['number'], and here is my code:

for a in in df['number'].index:
    if isinstance(df.ix[a]['number'], datetime.datetime):
       df.ix[a]['date'] = df.ix[a]['number']
       df.ix[a]['number'] = np.nan

but it seems it doesn't change the value of df.ix[a]['date'] or df.ix[a]['number'] at all. Or is there a better way to move a value from its current cell to its right cell?

btw type(df.ix[a]['number']) = float type(df.ix[a]['date']) = datetime.datetime

Thanks!!

Blue482
  • 2,926
  • 5
  • 29
  • 40
  • How was the dataframe originally defined? Perhaps there is a way to avoid this situation all together. – unutbu Aug 06 '14 at 18:33
  • 1
    You are chain indexing, see here: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy – Jeff Aug 06 '14 at 18:39
  • 1
    These chained index questions are getting tiresome. A google search of "pandas assignment not working" goes right to the docs. Voting to close. – Phillip Cloud Aug 06 '14 at 19:03

0 Answers0