我有一个要求,我需要应用一些聚合函数并根据一些用户输入过滤值 看看下面的代码:
Result := TRegex.IsMatch(List, '\bA\b');
一切运作良好,但当编译器读取行
时import pandas as pd
import numpy as np
from pandas import ExcelWriter
import tensorflow
donor_age = input("Enter Donor's Age: ")
donor_organ = input("Enter Organ to Donate: ")
writer = pd.ExcelWriter('Probability.xlsx', engine='xlsxwriter')
workbook = writer.book
df_success_rates = pd.read_excel('HealthChain.xlsx')
df_total=df_success_rates.groupby(['Donor_Age','Donor_Gender','Donor_Organ','SuccessfullCompletion'])\
.size().to_frame('total_count').reset_index().sort_values(['Donor_Age', 'total_count'], ascending=True)
df_total['Total_Operations']=df_total.groupby(['Donor_Age','Donor_Gender','Donor_Organ']).total_count.transform(np.sum)
df_total['Probability']=df_total['total_count']/df_total['Total_Operations']
#df_total=df_total[(df_total.Donor_Age == donor_age)]
df_total.to_excel(writer, sheet_name='Prob', engine='xlsxwriter', index=False)
writer.save()
workbook.close()
它会引发错误说明 documentation
但是当捐赠者的年龄被硬编码时,代码运行良好。
任何想法可能是问题的原因和相同的
的修复提前致谢!
答案 0 :(得分:1)
待办事项
donor_age = int(input("Enter Donor's Age: "))
input()返回一个字符串,看起来你要用一个不能比较的int来组合一个字符串。将输入转换为int或float或将其他年龄转换为str。