0

input
df.mean()
output:

a       4.112657e+07
b       1.197258e+00
c       4.172984e+05
d       2.461237e+02

input

df["a"].mean()

(correct) output:

41126569.99462365

type values in "a" col = int
others col have str values
why is this happening

Socka
  • 37
  • 5
  • 1
    use `astype(float)` –  Jan 12 '22 at 10:16
  • This is question is duplicate of [Format / Suppress Scientific Notation from Python Pandas Aggregation Results](https://stackoverflow.com/questions/21137150/format-suppress-scientific-notation-from-python-pandas-aggregation-results) – Chronial Jan 12 '22 at 10:27

3 Answers3

1

They are the same numbers, the thing is that the output its written in scientific notation. If you want the typical notation, you can use something like this: Format / Suppress Scientific Notation from Python Pandas Aggregation Results

CarlosCRO
  • 33
  • 7
0

4.112657e+07 and 41126569.99462365 are the same number. The first is just using scientific notation.

Chronial
  • 66,706
  • 14
  • 93
  • 99
0

If you want the mean of the other column, you have to change their type from str to float. Put .astype(float) to change the type to float, after that, you can do the mean.