python-“系列”对象没有属性“ iplot”

前端之家收集整理的这篇文章主要介绍了python-“系列”对象没有属性“ iplot” 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我一直在尝试解决最近2个小时的问题,并一直在简短地介绍如何解决错误-看过youtube视频,经历了stackoverflow,但我不知道哪里出了问题.
请注意,我正在使用Anaconda和Jupyter笔记本以及Python 3进行作业.

#Import Libraries
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

#Plotly Tools
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.offline as offline
offline.init_notebook_mode()
from plotly import tools
import plotly.tools as tls
init_notebook_mode(connected=True)

#Import CSV as a Pandas Dataframe
fp = pd.read_csv("gun-violence-data_01-2013_03-2018.csv")

#Confirm that dataset was properly loaded
fp.head()

导入库后,我对数据进行了一些清理,并将其放入数据帧“ fp_clean”中.当我尝试绘制时:

temp = fp_clean["state"].value_counts().head(30)
temp.iplot(kind='bar')

我不断收到以下错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-261d72eb2ae5> in <module>
      4 #temp.plot(kind='bar')
      5 temp = fp_clean["state"].value_counts().head(30)
----> 6 temp.iplot(kind='bar')
      7 #temp.iplot(kind='bar',xTitle = 'State name',yTitle = "# of incidents",title = 'Top States with highest number of Gun Violence',filename='Bar')
      8 #temp.plot(kind='bar')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self,name)
   4374             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   4375                 return self[name]
-> 4376             return object.__getattribute__(self,name)
   4377 
   4378     def __setattr__(self,name,value):

AttributeError: 'Series' object has no attribute 'iplot'

任何帮助将不胜感激!

谢谢!

最佳答案
此处的temp对象是一个pandas.series对象,当未以图方式链接时,该对象没有iplot方法.我们需要袖扣以将其密谋链接到熊猫并添加iplot方法

import cufflinks as cf
cf.go_offline()
cf.set_config_file(offline=False,world_readable=True)

之后,请尝试直接从数据框中绘图:

fp_clean["state"].iplot(kind="bar")

(如果没有袖扣,请使用:pip install cufflinks –upgrade)

猜你在找的Python相关文章