I am given a CSV that has two issues that is provided by a third party, out of my control to .
- Columns with Similar Names
- Columns with the Same Name
Different CSV will have different Similar Names
CSV File A
File Name,Column2[en],Column2[us],isPartOf,isPartOf
file1.tif,English,US English,USA,North America
file2.tif,English,,USA,
file3.tif,,US,,North America
CSV File B
File Name,Column2[fr],Column2[en],isPartOf,isPartOf
Is it possible using csv.DictReader to use startswith() to read multiple columns? Or do I need to create a map of the header row and map them separately before reading the CSV with DictReader?
Is it possible to read both to load the data from both columns with the same name? I know you can do something with dataframes in pandas, but I am not allowed to use Pandas.
#!/bin/env python3
import csv
with open("./test.csv") as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
for row in csv_reader:
print(row["isPartOf"],row["isPartOf"])
I run this using:
$ ./csvReader.py
North America North America
North America