[英]Change output format of Pandas dictionary in Python?
I have a csv file containing all the fruits data我有一个包含所有水果数据的 csv 文件
import pandas as pd
df = pd.read_csv('fruit_list.csv')
grouped_by_places = df.groupby('Places')
sort_quad = grouped_by_places['Quality']
max_quad = sort_quad.max()
But when i do print(max_quad.to_dict()), i can only get the default output format for dictionary但是当我打印(max_quad.to_dict())时,我只能获得字典的默认输出格式
{'A': 100, 'B': 70, 'C': 99, 'D': 84, 'E': 98, 'F': 89}
But i am trying to print the output as但我试图将输出打印为
A : 100.0
B : 70.0
C : 99.0
D : 84.0
E : 98.0
F : 89.0
Please help thanks for reading.请帮忙谢谢阅读。
Use Series.items
with print
and f-string
s:将Series.items
与print
和f-string
一起使用:
for k,v in max_quad.items():
print (f'{k} : {v}')
A : 100
B : 70
C : 99
D : 84
E : 98
F : 89
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.