【发布时间】:2020-06-22 14:49:50
【问题描述】:
我正在尝试根据用户输入计算我的数据框列中出现的次数:
ID State Comments
1 California Outsourced
2 Maryland NA
3 Maryland Outsourced
因此,如果用户输入“马里兰州”,Python 将返回“马里兰州的出现次数为 2”。我在网上找不到答案,所以我尝试这样做:
state_input = input("Enter the state: ")
while True:
if state_input == df['State']:
df['State'].eq(state_input).sum()
break
if cases > 0:
print(cases)
【问题讨论】:
标签: python loops dataframe input count