【发布时间】:2019-09-30 23:11:33
【问题描述】:
我正在使用 pandas 分析进行 eda 进程,对于特定的数据框我有错误
'DataFrame' 对象没有属性'name'
据我所知,这个属性不应该存在。我可以在执行 df.columns 时将其可视化,而在其他数据框中它不会出现。我也不能用 df.name = 'name here' 来改变它。有什么办法可以去掉吗?
我正在使用 Anaconda 安装的 Jupyter Lab 创建一个脚本。
我的代码:
import pandas_profiling as pp
df_planilhas.columns
Index(['VIAGEM', 'OT', 'DATA', 'HORA', 'CARGA', 'NF', 'TIPONF', 'CIA',
'ORIGEM', 'CIA', 'DESTINO', 'TRANSP', 'PLACA', 'FRETE', 'ITENS',
'CUBAGEMREAL', 'PESOREAL', 'VALOR', 'TIPO', 'COD', 'FLAG',
'OBSERVAÇÃO'],
dtype='object', **name=0**)
profile = pp.ProfileReport(df_planilhas)
AttributeError Traceback(最近调用 最后)在 ----> 1 个配置文件 = pp.ProfileReport(df_planilhas)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling__init__.py 在 init(self, df, **kwargs) 64 样本 = kwargs.get('sample', df.head()) 65 ---> 66 description_set = describe(df, **kwargs) 67 68 self.html = to_html(示例,
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\describe.py 在描述(df,bins,check_correlation,correlation_threshold, 相关覆盖,检查重新编码,池大小,**kwargs) 第413章 第414章 --> 415 'freq': {k: (base.get_groupby_statistic(df[k])[0] if variable_stats[k].type != base.S_TYPE_UNSUPPORTED else None) for k in df.columns}, 416'相关':{'pearson':dfcorrPear,'spearman':dfcorrSpear} 第417章
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\describe.py 在 (.0) 第413章 第414章 --> 415 'freq': {k: (base.get_groupby_statistic(df[k])[0] if variable_stats[k].type != base.S_TYPE_UNSUPPORTED else None) for k in df.columns}, 416'相关':{'pearson':dfcorrPear,'spearman':dfcorrSpear} 第417章
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\base.py 在 get_groupby_statistic(数据) 42 值计数和不同计数 43 """ ---> 44 如果 data.name 不是 None 并且 data.name 在 _VALUE_COUNTS_MEMO: 45 返回 _VALUE_COUNTS_MEMO[data.name] 46
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py 在 getattr(self, name) 4374 如果 self._info_axis._can_hold_identifiers_and_holds_name(名称):4375
返回自我[姓名] -> 4376 返回对象。getattribute(self, name) 4377 4378 def setattr(self, name, value):AttributeError: 'DataFrame' 对象没有属性 'name'
【问题讨论】:
-
我发现当我用 df_planilhas.columns = df_planilhas.iloc [0] 命名标题时会创建 name 属性。我尝试使用 tolist (df_planilhas.columns = df_planilhas.iloc [0] .tolist ()) 并且当我调用 df.columns 时 name = 0 不再出现,但是使用 profiling ('DataFrame'对象没有属性“名称”)