0

so I tried creating a new column name using df.column_name convention like here:

df2.DATE_CLOSED_calc= np.where(np.isnat(df2.DATE_CLOSED),np.datetime64('today'),df2.DATE_CLOSED)

but I got user warning, hence using recommendation by @AaronDT here, I just used df2['DATE_CLOSED_calc'] instead of df2.DATE_CLOSED_calc, then I didn't get a warning.

But what surprised is when I looked at df2.DATE_CLOSED_calc:

array([None, None, None, ..., None, None, None], dtype=object)

but df2['DATE_CLOSED_calc'] shows :

enter image description here

I always thought df.column_name or df['column_name'] referred to same column as Pandas series. Isn't that true? Why isn't it the case here? Thanks in advance!

Bharat Ram Ammu
  • 174
  • 2
  • 16
  • 1
    afaik you're only supposed to use the dot accessor for accessing the data, not assigning it. – molybdenum42 Oct 29 '19 at 10:14
  • It is probably because you alread assigned something to it in your code, probably in the line you showed on top. Try to restart your IDE and remove all the assign to that column, it should give the correct result. – Erfan Oct 29 '19 at 10:15
  • @molybdenum42 indeed, but now that I assigned df.column_name in one way and df['column_name'] in another way, can't I use df.column_name to access column of the data anymore, unless I change original assignment? – Bharat Ram Ammu Oct 29 '19 at 10:24
  • @Erfan I know I assigned something different, I know I can get what I want by specifying df['column_name'] instead of df.column_name. Question is more philosophical about how df.column_name changes its behaviour when it is used to assign instead of access – Bharat Ram Ammu Oct 29 '19 at 10:25
  • Have read in the link above. – Erfan Oct 29 '19 at 10:27
  • @BharatRamAmmu my understanding is that with the assignment you set a new attribute of the dataframe to that numpy array. This new attribute now overwrites the column accessor. – molybdenum42 Oct 29 '19 at 10:33

0 Answers0