嗨,我有一个数据框,如下所示:
response ticket
so service reset performed 123
reboot done 343
restart performed 223
no value 444
ticket created 765
我试着这样做:
import pandas as pd
df = pd.read_excel (r'C:\Users\Downloads\response.xlsx')
print (df)
count_other = 0
othersvocab = ['Service reset' , 'Reboot' , 'restart']
if df.response = othersvocab
{
count_other = count_other + 1
}
我想做的是计算有多少人有“OthersVocable”和有多少人没有。 我对Python真的是个新手,我不知道如何做到这一点
预期产出:
other ticketed
3 2
你能帮我弄明白吗,希望你的代码中发生了什么
考虑以下{^}:
以下是您的
othersvocab
:使用^{} :
我是在午休时间做这件事的,我不喜欢我的
for other in others
东西,有更好的方法使用pandas数据帧方法,你可以使用,但必须这样做因此,首先您需要解决的是,如果您想以我的方式执行此操作,您必须将
response
列和others
变量小写,这并不难(查找pandas apply和string操作符.lower)我在这里做的是首先循环循环循环列中的值
然后在这个循环中,我在
others
列表项上循环最后看看这些是否在列表中
我希望我仓促的反应能帮上忙
相关问题 更多 >
编程相关推荐