python - Python pandas DataFrame中math.log的结果是整数

标签 python pandas math

我有一个 DataFrame,所有值都是整数

        Millage  UsedMonth  PowerPS
1        261500        269      101
3        320000        211      125
8        230000        253      101
9        227990        255      125
13       256000        240      125
14       153000        242      150
17       142500        215      101
19       220000        268      125
21       202704        260      101
22       350000        246      101
25       331000        230      125
26       250000        226      125

我想计算log(Millage) 所以我使用了代码

x_trans=copy.deepcopy(x)
x_trans=x_trans.reset_index(drop=True)
x_trans.astype(float)

import math
for n in range(0,len(x_trans.Millage)):
    x_trans.Millage[n]=math.log(x_trans.Millage[n])
x_trans.UsedMonth[n]=math.log(x_trans.UsedMonth[n])

我得到了所有整数值

    Millage UsedMonth   PowerPS
0   12  5   101
1   12  5   125
2   12  5   101
3   12  5   125
4   12  5   125
5   11  5   150

这是 python 3,Jupyter 笔记本 我尝试了 math.log(100) 并得到4.605170185988092

我认为原因可能是 DataFrame 数据类型。 我怎样才能得到 float 形式的 log() 结果 谢谢

最佳答案

一种解决方案是简单地执行

x_trans['Millage'] = np.log(x_trans['Millage'])

关于python - Python pandas DataFrame中math.log的结果是整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51465661/

相关文章:

pandas - 在 datetimeindex 数据框中选择具有指定日期的行 - Pandas

math - 找到旋转矩形的边界矩形

math - 程序员的统计工具

python - 在 Ubuntu 上安装 django-cms 时出现环境错误

python - 使用 Pandas 从 csv 文件中读取标题信息

Python - Pandas 将所有其他列的列和统计度量分组为新列

Python ML - 如何最好地拯救 python ml 值数组

java - 一次进行 1、2 或 3 步到第 n 步的组合数‽

python - Pandas 将包含 nan 值的 float 列转换为 int 以进行合并操作

python - 将所有默认值移至一个 python 文件中