[英]Python Seaborn: getting AttributeError: 'str' object has no attribute 'get' when trying to plot
I'm working with a dataframe that only contains two columns, one categorical Peril
and one numerical Frequency
.我正在使用一个仅包含两列的数据框,一个分类
Peril
和一个数字Frequency
。 I am trying to create a bar chart but I keep getting an error:我正在尝试创建条形图,但我不断收到错误消息:
AttributeError: 'str' object has no attribute 'get'
AttributeError: 'str' 对象没有属性 'get'
when I run the following line:当我运行以下行时:
sns.catplot(data='df', x='Frequency', y='Peril', kind='bar')
I've successfully plotted using this code before.我之前已经成功地使用此代码进行了绘图。 I even went back and tried it in the old file and it works fine.
我什至回去在旧文件中尝试它,它工作正常。 I was originally thinking that maybe
Frequency
was being stored as a string instead of an integer, but when I ran df.info()
it returned我最初认为可能
Frequency
被存储为字符串而不是整数,但是当我运行df.info()
它返回
RangeIndex: 36 entries, 0 to 35
Data columns (total 2 columns):
Peril 36 non-null object
Frequency 36 non-null int64
dtypes: int64(1), object(1)
memory usage: 656.0+ bytes
Currently stuck on how to resolve this issue.目前停留在如何解决这个问题上。
Your dataframe variable is wrapped in quotes when it should not be.您的数据帧变量在不应该用引号括起来的时候用引号括起来。 Remove the quotes and it should work.
删除引号,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.