输入学院编号,输出学院人数
import pandas as pd
df = pd.read_csv('./surveyRes.csv')
df.head()
dicts = df.set_index('number')['college'].to_dict()
print(dicts)
num = int(input())
for num in dicts.values():
print(dicts.count(num))
import pandas as pd
df = pd.read_csv('./surveyRes.csv')
df.head()
dicts = df.set_index('number')['college'].to_dict()
print(dicts)
num = int(input())
for num in dicts.values():
print(dicts.count(num))
正确代码如下,如果有帮助,请点击一下采纳谢谢:
import pandas as pd
df = pd.read_csv('./surveyRes.csv')
df.head()
dicts = df.set_index('number')['college'].to_dict()
print(dicts)
num = int(input())
count = 0
for key, value in dicts.items():
if key == num:
count += 1
print(count)