gpt4 book ai didi

python - Pandas: AttributeError: 'Series' 对象没有属性 'style'

转载 作者:行者123 更新时间:2023-12-03 23:04:24 28 4
gpt4 key购买 nike

我正在尝试为某个输出着色,就像这样

df['a'] = df['a'].fillna(df['b'].map(s)).style.applymap(lambda x: "background-color:yellow")
所以我得到了错误
AttributeError: 'Series' object has no attribute 'style'
我怎样才能使它正确并只为由此产生的输出着色?

最佳答案

有人叫道,style格式化程序用于数据帧,您正在使用系列。您可以作为 .style 的序言调用 .to_frame()例如df['a'] = df['a'].fillna(df['b'].map(s)).to_frame().style.applymap(lambda x: "background-color:yellow")或者,不太明确地,使用 DataFrame 而不是 Series 将您的列名包装在另一组括号中,例如df[['a']]而不是 df['a']

关于python - Pandas: AttributeError: 'Series' 对象没有属性 'style',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63546354/

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