【问题标题】:How to convert scientic notation of my code?如何转换我的代码的科学记数法?
【发布时间】:2019-11-26 14:48:00
【问题描述】:

我创建了一个函数来检查 pandas 数据框中的值范围。但输出是用科学计数法产生所有值。 当我 select_dtypes 只包含 int 时,我没有遇到这个问题。只有当我包含浮动时才会发生这种情况。如何获得非科学值?

# Function to check range of value in a col.
def value_range(col):
    max = data[col].max()
    min = data[col].min()
    return max-min

# value_range('total_revenue')

numerical_data = data.select_dtypes(include=[float, int]).columns
print(value_range(numerical_data))

输出:

Unnamed: 0                               3.081290e+05
number_of_sessions                       1.340000e+02
total_bounce                             1.080000e+02
total_hits                               3.706000e+03
days_difference_from_last_first_visit    1.800000e+02
transactions                             2.500000e+01
total_revenue                            2.312950e+10
organic_search                           1.110000e+02
direct                                   8.300000e+01
referral                                 1.070000e+02
social                                   1.120000e+02
paid_search                              4.400000e+01
affiliates                               3.700000e+01
display                                  8.500000e+01
target_if_purchase                       1.000000e+00
target_total_revenue                     2.039400e+09
dtype: float64

【问题讨论】:

  • this answer 是关于抑制科学记数法的吗?还发现this one
  • 尝试format打印。类似"{:.2f}".format(...)

标签: python-3.x pandas


【解决方案1】:

value_range(numerical_data).apply(lambda x: format(x, 'f')) 解决了这个问题。谢谢 Sparrow1029。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2022-01-24
    • 2014-09-25
    • 2021-12-23
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    相关资源
    最近更新 更多