【问题标题】:Why are some of my columns of my data not recognized on my data frame after importing a csv file to python将 csv 文件导入 python 后,为什么我的某些数据列在我的数据框中无法识别
【发布时间】:2020-05-12 12:56:57
【问题描述】:

这是我的代码

Import pandas as pd
finance=pd.read_csv("C:/Users/hp/Desktop/Financial Sample.csv")

finance.Profit.describe()

还有错误

AttributeError Traceback (最近一次调用最后一次) in ----> 1 finance.Profit.describe() ~\Anaconda3\lib\site-packages\pandas\core\generic.py in getattr(self, name) 5177 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5178 return self[name] -> 5179 return object.getattribute(self, name) 5180 5181 def setattr(self, name, value): AttributeError: 'DataFrame' object has no attribute 'Profit'

【问题讨论】:

  • print (finance.head()) 是什么?
  • 分隔符是, 吗?
  • 需要更多信息,例如标题样本和 csv 的示例行。您也可以通过将它们包含在反引号中来格​​式化您的代码

标签: python pandas dataframe


【解决方案1】:

根据您提交的错误 这是描述利润列的正确语法

finance['Profit'].describe()

【讨论】:

    【解决方案2】:

    如果列名已被解析为它的保存方式(区分大小写),则此语法将起作用:

    finance['Profit'].describe()
    

    但是,有时您的列名称在读取后可能会在其前面添加字符,因此实际调用可能会导致错误。为避免这种情况,您还可以使用.iloc()

    finance.iloc[:,"(column number here, starts from 0)"].describe()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多