在数据帧中的列除(或任何其他数学运算符)之前进行类型转换 [英] Typecasting before division (or any other mathematical operator) of columns in dataframes
本文介绍了在数据帧中的列除(或任何其他数学运算符)之前进行类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据列,列为A
,B
.我需要添加一列C
,该列基本上是A
中的条目除以B
中的条目的方式.
I have a dataframe with columns A
, B
. I need to add a column C
which is basically the division of entries in A
by the entries in B
.
我尝试过:
df['C'] = df['A'] / df['B']
但是在执行此操作之前,我需要转换为double或float.我应该如何键入列的dtype
?
But I need to convert to double or float before I do this. How should I type-cast the dtype
of the columns?
谢谢.
推荐答案
如何
df['C'] = df['A'] * 1.0 / df['B']
这篇关于在数据帧中的列除(或任何其他数学运算符)之前进行类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文