Last active
July 5, 2024 08:59
-
-
Save swarupmtb/ea8887460f9277ce101d699336faf0c8 to your computer and use it in GitHub Desktop.
CSV to Column Value in to 1 line Separated with Coma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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