AppleStore.csv being stored as list of strings and not list of lists

My Code:

from csv import reader

opened_file = open('googleplaystore.csv' , encoding='utf8')
read_file = reader(opened_file)
googleplaystore = list(opened_file)
googleplaystore_header_str = googleplaystore[0]
googleplaystore_data = list(googleplaystore[1:])
googleplaystore_header = googleplaystore_header_str.split(",")

print(len(googleplaystore_header))
print(googleplaystore_header)
print('\n')
print(len(googleplaystore_data[0]))
print(googleplaystore_data[0])

What I expected to happen:
I would think that the data section would be stored as a list of lists with each row reporting back as a list similar to the header (which is only a list because I added the .split line - was also stored as a string originally)

What actually happened:
Each apps data is stored as a string within the data list. This exercise requires comparing length of each row in the data variable to the header length which is not possible unless it is stored as a list of list. I can’t figure out how to make the data a list of lists.

13
['App', 'Category', 'Rating', 'Reviews', 'Size', 'Installs', 'Type', 'Price', 'Content Rating', 'Genres', 'Last Updated', 'Current Ver', 'Android Ver\n']


150
Photo Editor & Candy Camera & Grid & ScrapBook,ART_AND_DESIGN,4.1,159,19M,"10,000+",Free,0,Everyone,Art & Design,"January 7, 2018",1.0.0,4.0.3 and up

Hello @EvanJohnson welcome to the community!

Should be:
googleplaystore = list(read_file)

1 Like

Hi @EvanJohnson

In this project there are actually three steps before getting the data ready to be used. First we need to open the .csv file, the read it and then convert the read file into a list of list using list()

It is clear that you understand that steps from your code. But finally the file that we need to work in order to make it into a list is the read file, not the opened file.

Like this stackoverflow thread says

Opening a file allows you to read or write to it (depending on the flag you pass as the second argument), whereas reading it actually pulls the data from a file that is typcially saved into a variable for processing or printed as output.

You do not always read from a file once it is opened.

Like it was mentioned by monorienaghogho you have to use

googleplaystore = list(read_file)
1 Like