我正在尝试运行以下代码:
#calculate the mean vaule for "stroke" column
avg_stroke=df['stroke'].astype('float').mean(axis=0)
print("Average of stroke:", avg_stroke)
但是,我不断遇到以下错误:
float() argument must be a string or a number, not 'method'` on this code.
我在脚本的不同部分使用了相同的代码结构,并实现了一个很好的干净的意思:
#Write your code below and press Shift+Enter to execute
avg_norm_loss = df["normalized-losses"].astype("float").mean(axis=0)
print("Average of normalized-losses:", avg_norm_loss)
我已经从这些SE答案中排除了任何建议/答案:
您知道该列中存在值为“”的字符串吗? 你必须先移除它。除此之外,代码对我有效
相关问题 更多 >
编程相关推荐