CRoNiC
CRoNiC

Reputation: 409

df.describe() Type suddenly changed Values missing now

I used df.describe() to get mean, 25% Quartile, 75% Quartile. Everything worked perfectly as I wished with the numeric description. Now I deleted some columns of the dataframe and suddenly it gives me a categorial description and so I can't use mean, 25%,... anymore.

Everything besides the number of columns (96 before, now 49) remained the same.

Can anyone explain why this happened?

The column names are W01,W02,...W96 where everything worked fine. (I got a numeric description). Now the names are W01,W02,...W49 and now I get a categorial description)

BEFORE:

df.describe()
                    W01
    count  1.010000e+02
    mean   1.088165e+06
    std    1.071501e+06
    min    0.000000e+00
    25%    3.186370e+05
    50%    1.195219e+06
    75%    1.475124e+06
    max    9.774923e+06

AFTER:

  df.describe()
            W01
    count   101
    unique  100
    top       0
    freq      2

In the end the logical Error appears, that the column "25%" cant be found but that's not my question.

What can I do to avoid the change of the description?

EDIT: both dataframes are created from a csv that is absolutly identical besides the one with 49 columns has less columns...

Upvotes: 0

Views: 253

Answers (1)

ansev
ansev

Reputation: 30930

You can use pandas.DataFrame.astype to convert to float:

df.astype(float)

Upvotes: 1

Related Questions