I am learning python and I have been stuck trying to figure why this script won't work.
I have a csv file with a header, and I input it into terminal as the an argument
The following script works fine, it lets me reiterate through each line of my csv file
import sys
input = open(sys.argv[1], 'r')
for line in input:
print(line)
But when I try to convert my column index and headers into a dictionary
import sys
import pandas as pd
input = open(sys.argv[1], 'r')
csvfile = pd.read_csv(input)
columnheader_dict= {csvfile.columns.get_loc(i):i for i in csvfile.columns}
for line in input:
print(line)
print(line) doesnt print anything. Why won't it let me reiterate through each row in my csv file?