0

I've created a function to check the range of values in a pandas dataframe. But the output is producing all values with scientific notation. When I select_dtypes to include only int, I don't get this problem. It only happens when I include float. How can I get non-scientific values?

# 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))

Out:

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
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
spidermarn
  • 959
  • 1
  • 10
  • 18
  • 2
    Is [this answer](https://stackoverflow.com/questions/21137150/format-suppress-scientific-notation-from-python-pandas-aggregation-results#answer-21140339) about suppressing scientific notation what you are looking for? Also found [this one](https://stackoverflow.com/questions/40347689/dataframe-describe-suppress-scientific-notation/47207283#answer-47207283) – Sparrow1029 Jul 17 '19 at 17:45
  • try `format`ing the print. something like `"{:.2f}".format(...)` – Tomerikoo Jul 17 '19 at 17:57

1 Answers1

1

value_range(numerical_data).apply(lambda x: format(x, 'f')) solves the problem. Thanks Sparrow1029.

spidermarn
  • 959
  • 1
  • 10
  • 18