Justin T Justin T - 1 year ago 141
Python Question

Reading an excel data set saved as CSV file in pandas

There is a very similar question to the one I am about to ask posted here:

Reading an Excel file in python using pandas

Except when I attempt to use the solutions posted here I am countered with

AttributeError: 'DataFrame' object has no attribute 'read'

All I want to do is convert this excel sheet into the pandas format so that I can preform data analysis on some of the subjects of my table. I am super new to this so any information, advice, feedback or whatever that anybody could toss my way would be greatly appreciated.

Heres my code:

import pandas
file = pandas.read_csv('FILENAME.csv', 'rb')
# reads specified file name from my computer in Pandas format
print file.read()

By the way, I also tried running the same query with
file = pandas.read_excel('FILENAME.csv', 'rb') returning the same error.

Finally, when I try to resave the file as a .xlsx I am unable to open the document.


Answer Source

Your error message means exactly what it says: AttributeError: 'DataFrame' object has no attribute 'read'

When you use pandas.read_csv you're actually reading the csv file into a dataframe. BTW, you don't need the 'rb'

df = pandas.read_csv('FILENAME.csv')

You can print (df) but you can not do print(df.read()) because the dataframe object doesn't have a .read() attribute. This is what's causing your error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download