Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug on astype pandas?

I am working with timedeltas and it seems this code

copy_for_U.Time.astype('timedelta64[m]',copy=False);

does not change the dataframe - as it should, if I understood correctly from the doc, where it says:

Signature: full_df.Time.astype(dtype, copy=True, raise_on_error=True, **kwargs) Docstring: Cast object to input numpy.dtype Return a copy when copy = True (be really careful with this!)

like image 942
jjrr Avatar asked Jan 10 '17 10:01

jjrr


1 Answers

In order for the changes to be applied to the dataframe, one needs to assign the dataframe to the variable one wants (or pass inplace=True - this may be a nice thread to read).

Also, when doing that, you don't need to pass the copy=False, as @jezrael suggests.

Given that, this should solve your problem

copy_for_U.Time = copy_for_U.Time.astype('timedelta64[m]') 
like image 194
Gonçalo Peres Avatar answered Sep 24 '22 09:09

Gonçalo Peres