The len( ) command is returning a larger value than expected

https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/2/opening-and-exploring-the-data

My Code: print('Number of columns:', len(dataset[0]))

What I expected to happen:
I expected this result: “Number of columns: 16”

What actually happened:
The result I got was: “Number of columns: 93”

There was no output error. However, it appears that all the characters (letters, spaces, underscores, hyphens, etc) are being counted, instead of elements in the list.

Hi! @bennie4hon
Can you share your code for the full function? with output for the same on the dataset.

Here it is @harsh.raizada:

opened_file_1 = open(‘AppleStore.csv’)
from csv import reader
read_file_1 = reader(opened_file_1)
apple_apps = list(opened_file_1)
apple_header = apple_apps[0]
apple_apps = apple_apps[1:]

opened_file_2 = open(‘googleplaystore.csv’)
read_file_2 = reader(opened_file_2)
android_apps = list(opened_file_2)
android_header = android_apps[0]
android_apps = android_apps[1:]

def explore_data(dataset, start, end, rows_and_columns=False):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print(row)
print(’\n’) # adds a new (empty) line after each row

if rows_and_columns:
    print('Number of rows:', len(dataset))
    print('Number of columns:', len(dataset[0]))

explore_data(apple_apps, 0, 3, True)
explore_data(android_apps, 0, 3, True)

###Here is the OUTPUT of my code: ###

284882215,Facebook,389879808,USD,0.0,2974676,212,3.5,3.5,95.0,4+,Social Networking,37,1,29,1

389801252,Instagram,113954816,USD,0.0,2161558,1289,4.5,4.0,10.23,12+,Photo & Video,37,0,29,1

529479190, Clash of Clans,116476928,USD,0.0,2130805,579,4.5,4.5,9.24.12,9+,Games,38,5,18,1

Number of rows: 7197
Number of columns: 93

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

Coloring book moana,ART_AND_DESIGN,3.9,967,14M,“500,000+”,Free,0,Everyone,Art & Design;Pretend Play,“January 15, 2018”,2.0.0,4.0.3 and up

“U Launcher Lite – FREE Live Cool Themes, Hide Apps”,ART_AND_DESIGN,4.7,87510,8.7M,“5,000,000+”,Free,0,Everyone,Art & Design,“August 1, 2018”,1.2.4,4.0.3 and up

Number of rows: 10841
Number of columns: 150

@bennie4hon Thank you for sharing.
Here is the solution:
In your code: you are passing the wrong variable for list conversion (In last line i.e apple_apps)

opened_file_1 = open(‘AppleStore.csv’)
from csv import reader
read_file_1 = reader(opened_file_1)
apple_apps = list(opened_file_1)

To make a list of data you first open & read the file and then you have to pass the read file which is read_file_1 to do list conversion in apple_apps not opened_file_1 because if you convert open file to list then it will not get properly parsed or formatted and will give issues, so the correct code will be:

opened_file_1 = open(‘AppleStore.csv’)
from csv import reader
read_file_1 = reader(opened_file_1)
apple_apps = list(read_file_1)

You will now get a number of columns: 16

Hope it helps!

Thanks a lot @harsh.raizada. This was really helpful. I appreciate :pray: