Oct-02-2021, 01:00 AM
Not sure I understand the request, but this will get you column 4 as a comma separated string, if that is what you want.
You could write string to a csv file.
You can probably do this more elegantly using pandas.
You could write string to a csv file.
You can probably do this more elegantly using pandas.
# read straight to a dictionary # the columns are: fname, lname, department, birthday_month # so column 4 is birthday_month import csv path = '/home/pedro/myPython/csv/' with open(path + 'employees.txt', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) name_records = list(csv_reader) # gives a list of dictionaries where the key is the column header # here column 4 is 'birthday_month' # get all 'birthday_month' records as a comma-separated string string = '' for d in name_records: string = string + d['birthday_month'] + ',' # get rid of the last comma string = string[0:-1]