简体   繁体   English

Python Seaborn:获取AttributeError:尝试绘图时'str'对象没有属性'get'

[英]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.

相关问题 Python AttributeError:“ str”对象没有属性“ get” - Python AttributeError: 'str' object has no attribute 'get' “AttributeError: 'DataFrameGroupBy' object has no attribute 'get'” 当试图在 Seaborn 的.boxplot() 中对 plot 分组数据进行装箱时 - “AttributeError: 'DataFrameGroupBy' object has no attribute 'get'” when attempting to box plot grouped data in Seaborn's .boxplot() 尝试使用 Jira Python API 获取数据时出现错误 [AttributeError: 'bool' object has no attribute 'error'] - Getting error [ AttributeError: 'bool' object has no attribute 'error' ] when trying to get data using Jira Python API 尝试使用 Django 设置 SendGrid 的电子邮件 API 时出现此错误 - AttributeError: 'str' object has no attribute 'get' - Getting this error while trying to set SendGrid's email API with Django - AttributeError: 'str' object has no attribute 'get' 获取 AttributeError: 'str' object 在尝试调用方法时没有属性 'readlines' - Getting AttributeError: 'str' object has no attribute 'readlines' when trying to call method AttributeError: 'str' 对象在尝试使用 writerow 时没有属性 'keys' - AttributeError: 'str' object has no attribute 'keys' when trying to use writerow AttributeError: 'str' 对象在尝试从 tkinter Entry Widget 获取字符串信息时没有属性 'get' - AttributeError: 'str' object has no attribute 'get' when trying to get string information from a tkinter Entry Widget Trac AttributeError:尝试获取系统中可用的组件时,“ str”对象没有属性“ db_query”错误 - Trac AttributeError: 'str' object has no attribute 'db_query' error when trying to get Components available in the system AttributeError: 'str' 对象在 Seaborn 和 Scatterplot 中没有属性 'view' - AttributeError: 'str' object has no attribute 'view' in Seaborn , Scatterplot 获取 AttributeError: 'str' 对象在遍历 json 文件时没有属性 'get' - Getting AttributeError: 'str' object has no attribute 'get' when traversing through json file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM