def explore_data(dataset, start, end, rows_and_columns=False):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print('Number of rows:', len(dataset))
print('Number of columns:', len(dataset)))
explore_data(android, 0, 3, True)
How does the program know that ‘len(dataset)’ is the length of the rows and that ‘len(dataset’ is the length of the columns?
Kindly refer to my illustration below.
dataset refers to the header row of the dataset. Recall that python is
zero-indexed thus indexing starts at
0. The red outline illustrates all the elements in
len(dataset) gives the number of columns (in this case
6, again since python is zero indexed–column 0, which is the company name to column 6–the URL).
dataset refers to the next row of values after the header as illustrated by the green box.
len(dataset) refers to the total number of rows in the dataset since a slice is not specified.
In this case, after the csv file is extracted, it would look something like this:
company data = [ [ "Company Name", "Address: Street 1", "Address: Street 2",
"Address: State", "Address: Zip", "URL"] ,
["Dodgit", "334 Melo Drive", "", "Menlo", "CA", "84432". "http://dodgit.com"] ,
Note that the data is a
2D array (or a list of lists) since it contains both rows and columns. A comma (or sometimes
\n) seperates the rows. Thus,
len(dataset) counts the number of such rows or 1D arrays, while
len(dataset) counts the individual elements in the array.
Hope this helps!
No worries @s.cook20. Happy learning!