Grace
Grace

Reputation: 1

Why are some of my columns of my data not recognized on my data frame after importing a csv file to python

Here is my code

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

finance.Profit.describe()

And the error

AttributeError Traceback (most recent call last) 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'

Upvotes: 0

Views: 76

Answers (2)

Joe
Joe

Reputation: 889

This syntax will work if the column name has been parsed as how it was saved (case-sensitive):

finance['Profit'].describe()

However, sometimes the name of your column can have added characters before it after reading so the actual call might result in an error. To avoid this, you can also use .iloc()

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

Upvotes: 0

Manish Chaudhary
Manish Chaudhary

Reputation: 508

according to your submitted error here is correct syntax to describe Profit Column

finance['Profit'].describe()

Upvotes: 0

Related Questions