0
Follow
0
View

Creating a dictionary of series from a dataframe

jt285088419 注册会员
2023-01-24 22:48

Try:

output = {x.iat[0,0]: pd.Series(x.set_index("col_1").iloc[1:,0], name=x.iat[0,0]) for _, x in df.groupby("group")}

>>> output
{'Fruit': col_1
 Apple     0.25
 Pear      0.25
 Orange     0.5
 Name: Fruit, dtype: object,
 'Vegtable': col_1
 Pea       0.6
 Lettus    0.4
 Name: Vegtable, dtype: object,
 'Meat': col_1
 Beef    1
 Name: Meat, dtype: object}

About the Author

Question Info

Publish Time
2023-01-24 22:48
Update Time
2023-01-24 22:48

Related Question

在/form字段'roof_age'中输入一个数字,但得到('1',)

截至2022年6月26日,Microsoft Edge不再重用子选项卡

如何排除$(document).off('click')触发的特定元素

在Helm模板中传递Dictionary作为参数

onlyoffice保存失败问题

发现的ArrayoutofBounds异常无法解决[重复]

sizdof结构体嵌套

使用“Microsoft Print to PDF”和Java将文档转换为PDF

Need suggestion in deciding the type of the parameter(query/header) in an existing REST API [closed]

EOF运用,请各位看看为什么没有输出