简体   繁体   English

astype 熊猫上的错误?

[英]Bug on astype pandas?

I am working with timedeltas and it seems this code我正在使用 timedeltas,似乎这段代码

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).为了将更改应用于数据帧,需要将数据帧分配给所需的变量(或传递inplace=True -可能是一个很好的阅读线程)。

Also, when doing that, you don't need to pass the copy=False , as @jezrael suggests .此外,这样做时,您不需要传递copy=False ,正如@jezrael 建议的那样

Given that, this should solve your problem鉴于此,这应该可以解决您的问题

copy_for_U.Time = copy_for_U.Time.astype('timedelta64[m]') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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