jjrr
jjrr

Reputation: 1148

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!)

Upvotes: 7

Views: 967

Answers (1)

Gonçalo Peres
Gonçalo Peres

Reputation: 13622

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]') 

Upvotes: 1

Related Questions