Skip to content

Instantly share code, notes, and snippets.

@swarupmtb
Last active July 5, 2024 08:59
Show Gist options
  • Save swarupmtb/ea8887460f9277ce101d699336faf0c8 to your computer and use it in GitHub Desktop.
Save swarupmtb/ea8887460f9277ce101d699336faf0c8 to your computer and use it in GitHub Desktop.
CSV to Column Value in to 1 line Separated with Coma
import csv
def column_to_single_line(csv_file, column_name):
column_values = []
with open(csv_file, mode='r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
column_values.append(row[column_name])
result = ', '.join(column_values)
return result
csv_file = 'tmalef.csv'
column_name = 'Mobile'
result = column_to_single_line(csv_file, column_name)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment