gpt4 book ai didi

python - 将 pandas set_value 转换为 at[]

转载 作者:行者123 更新时间:2023-12-01 08:05:57 25 4
gpt4 key购买 nike

我有一个代码

df.set_value(index, 'review_category', 'No_Reviews')

它给我警告如下:

FutureWarning: set_value is deprecated and will be removed in a future release. Please use .at[] or .iat[] accessors instead    

我尝试如下转换此代码:

df.at[index, 'review_category'] = 'No_Reviews'  

现在我收到以下错误:

'DataFrame' object has no attribute 'review_category'   

最佳答案

  • df.loc 从索引中获取具有特定标签的行(或列)。

  • df.iloc 获取索引中特定位置的行(或列)(所以它只需要整数)。

在您的示例中,假设您的索引从 0,1,2... 等开始,您可以使用

    df.iloc[index]['review_category'] = 'No_Reviews'  

关于python - 将 pandas set_value 转换为 at[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55530336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com