I can’t figure out how to get column names in the Project. This is my code:
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
for col_name in row[0]:
print(col_name)
if rows_and_columns == True:
print('Number of rows:', len(dataset))
print('Number of columns:', len(dataset[0]))
The names of the columns are actually stored in the header variables (android_header and apple_header). If you want to see those, just enter print(android_header) in a cell so that you can see the column names.
Here is what went wrong with this section of code:
for col_name in row[0]:
print(col_name)
In the loop, row[0] is going to be the first element of the row, which for the android dataset is the app name, a string. When we loop through the string, col_name will be an individual character of the string. So print(col_name) will print each individual character of the app name.
I hope that helps. Let me know if there was something else you were hoping to get your function to do instead.