[英]Function to filter and apply calculation error in python
import pandas as pd导入 pandas 作为 pd
def bonus_calculation(dataframe): def bonus_calculation(数据框):
df2 = pd.read_csv("C:\\Users\\ThisI\\employees_update.csv")
active_employees['bonus'] = df2[df2["end_date"].isnull()].loc[:, "salary"] * 1.2
return active_employees
bonus_calculation(active_employees)奖金计算(active_employees)
I get this error message: :7: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.我收到此错误消息::7:SettingWithCopyWarning:试图在 DataFrame 的切片副本上设置值。 Try using.loc[row_indexer,col_indexer] = value instead
尝试改用 .loc[row_indexer,col_indexer] = value
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy active_employees['bonus'] = df2[df2["end_date"].isnull()].loc[:, "salary"] * 1.2请参阅文档中的警告: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy active_employees['bonus'] = df2[df2 ["end_date"].isnull()].loc[:, "salary"] * 1.2
Can someone help me on this?有人可以帮我吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.