如何在PANDAS DataFrame的任何列中有关其他列中的数字数据(映射)更改分类数据?
我想用pandas dataframe中的aqi_bucket列映射AQI列 我尝试使用循环,但无法得到
for aqi in df['AQI']:
col1,col2 = df['AQI'],df['AQI_Bucket']
_col1,_col2 = col1[0],col2[0]
if df[aqi] == df['AQI_Bucket']:
if pd.isnull(_col2):
if _col1 in range(51):
_col2 = "Good"
elif _col1 in range(51, 101):
_col2 = "Satisfactory"
elif _col1 in range(101,201):
_col2 = "Moderate"
elif _col1 in range(201, 301):
_col2 = "Poor"
elif _col1 in range(301, 401):
_col2 == "Very Poor"
elif _col1 in range(401, 500):
_col2 == "Severe"
i want to map the the AQI column with AQI_Bucket column in pandas dataframe
i tried it using for loop but couldnt get it
for aqi in df['AQI']:
col1,col2 = df['AQI'],df['AQI_Bucket']
_col1,_col2 = col1[0],col2[0]
if df[aqi] == df['AQI_Bucket']:
if pd.isnull(_col2):
if _col1 in range(51):
_col2 = "Good"
elif _col1 in range(51, 101):
_col2 = "Satisfactory"
elif _col1 in range(101,201):
_col2 = "Moderate"
elif _col1 in range(201, 301):
_col2 = "Poor"
elif _col1 in range(301, 401):
_col2 == "Very Poor"
elif _col1 in range(401, 500):
_col2 == "Severe"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定我知道您要在这里做什么,并且您绝对应该使用
.cut()
方法:如果不是您想要的,请让我知道,我会删除我的答案,否则请检查标记它✅
I'm pretty sure I know what you're trying to do here, and you should definitely use the
.cut()
method:If it's not what you were looking for, please let me know and I'll delete my answer, otherwise check mark it ✅