📌  相关文章
📜  python 从分组数据框中获取列 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:43.786000             🧑  作者: Mango

代码示例1
# You can also reset_index() on your groupby result to get back a dataframe with the name column now accessible.

import pandas as pd
df = pd.DataFrame({"a":[1,1,3], "b":[4,5.5,6], "c":[7,8,9], "name":["hello","hello","foo"]})

df_grouped = df.groupby(["a", "name"]).median().reset_index() # Resetting the index makes the column accessible

df_grouped.name

 #Output:
 0    hello
 1      foo