Note When working with heterogeneous data, the dtype of the resulting ndarray will be chosen to accommodate all of the data involved. For example, if strings are involved, the result will be of object dtype. If there are only floats and integers, the resulting array will be of float dtype.
至于在整个数据帧中用,替换.,请用replace替换regex = True:
df = df.replace(',','.',regex=True)
# or
df.replace(',','.',regex=True, inplace = True)
尽管dtype确实是“object”,但当将type()函数单独应用于列标签时,您会发现它们实际上属于类“str”。 所以这很好。你知道吗
关于你关于替换的问题,我建议如下:
在
pandas
中没有字符串dtype
。如docs中所述:至于在整个数据帧中用
,
替换.
,请用replace
替换regex = True
:例如:如果您的数据帧
df
看起来像:然后:
相关问题 更多 >
编程相关推荐