【发布时间】:2022-11-02 03:20:24
【问题描述】:
我正在使用的数据表按以下列组织:“国家”、“互联网用户”和“人口”。我能够计算并打印使用互联网的最大人口百分比,但是如何打印具有该最大百分比的国家/地区名称。例如,印度尼西亚的最大值为 94%,但我只能打印“94%”。我想打印“印度尼西亚 94%”。
import pandas as pd
import matplotlib.pyplot as plt
pop = pd.read_csv('country_internet.csv')
op = input("Enter output file name: ")
pop['Percentage'] = round(pop['Internet users']/pop['Population']*100,2)
pop.plot(x = 'Country', y = 'Percentage')
print("Maximum percentage of all countries:",pop['Percentage'].max(),"%")
plt.show()
fig = plt.gcf()
fig.savefig(op)
【问题讨论】:
-
你可以试试
row = pop.iloc[pop['Percentage'].idxmax()] print(row['Country'])等。