How to get column names?

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]))

from csv import reader

open_file1 = open(‘googleplaystore.csv’)
read_file1 = reader(open_file1)
android = list(read_file1)
android_header = android[0]
android = android[1:]

open_file2 = open(‘AppleStore.csv’)
read_file2 = reader(open_file2)
apple = list(read_file2)
apple_header = apple[0]
apple = apple[1:]

first = explore_data(android, 1, 5, rows_and_columns=True)

Hi @MiloBogdanovi , welcome to the community!

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.

Thank you. Your explanation cleared it up.