列的Python分组

时间:2019-05-01 10:27:25

标签: python bigdata

从事一些机器学习,需要进行一些数据探索

print(df.groupby('model_new')['MFG']) 

给我:

当前输出:

**MFG        model_new**   Count
HGST         model1          2
HGST         model2          434
HGST         model3          3
Toshiba      model1          12
Toshiba      model2          3

expected output
    MFG      model_count
    HGST           3
    Toshiba        2

.....

1 个答案:

答案 0 :(得分:0)

这应该可以回答您的问题:

@font-face {
font-family: "CustomFont";
src: url("CustomFont.eot");
src: url("CustomFont.woff") format("woff"),
url("CustomFont.otf") format("opentype"),
url("CustomFont.svg#filename") format("svg");
}

,如果需要唯一值:

pd.DataFrame(df.groupby('MFG')['model_new'].count())

在您的情况下,它们都给出相同的结果,但对于其他DataFrame,它可能会更改。