ivan
ivan

Reputation: 81

python pandas strange group by

I have a DataFrame df:

                ga:browser ga:users
    0               Chrome     1351
    1             MRCHROME      870
    2               Chrome      630
    3            YaBrowser      601
    4            YaBrowser      567
    5              Firefox      541
.............

its ok If I group by isDataFrame im get

print(df[["ga:browser", 'ga:users']].groupby(["ga:browser"])['ga:users'].sum()) 

its return

ga:browser
Android Browser                                                      16394331
BlackBerry                                                                  2
BrowserNG                                                                   3
Chrome                      1351630526198100776663625656514239363331242221...
Edge                                                                   132332
Firefox                      541149412827211686554433332222221111111111111111
Internet Explorer                                                 20349403171
Iron                                                                        1
MRCHROME                                                                  870

How i can group this?

Upvotes: 0

Views: 55

Answers (1)

Stefan
Stefan

Reputation: 42875

Check the dtype of ga:users with df.info(). If it's not int64 but rather object (which implies string, and your output looks like strings being concatenated), do

df['ga:users'] =df[['ga:users']].astype(int)

Upvotes: 1

Related Questions