将csv文件导入python

时间:2020-01-27 06:47:06

标签: python pandas dataframe

这是我的代码

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

finance.Profit.describe()

还有错误

AttributeError Traceback(最近一次通话最后一次)位于----> 1中。 getattr (自身)5177 if self._info_axis._can_hold_identifiers_and_holds_name(名称):5178返回self [名称]-> 5179返回对象。 getattribute (自身,名称)5180 5181 def setattr < / strong>((自身,名称,值):AttributeError:“ DataFrame”对象没有属性“ Profit”

2 个答案:

答案 0 :(得分:0)

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

finance['Profit'].describe()

答案 1 :(得分:0)

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

finance['Profit'].describe()

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

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