简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM