I have a huge csv file with 4 columns. i'm trying to convert them into a data dictionary. the first column [0] should be the master key. when i try to use the dictionary i get a key error.
columns in csv file:Code Description Category Detail
with open('sample.csv') as f:
reader = csv.reader(f)
next(reader,None)
code= {}
description= {}
category = {}
detail = {}
for row in reader:
code = {row[0]:row[1]}
description = {row[0]:row[2]}
category = {row[0]:row[3]}
detail = {row[0]:row[4]}
output: {101:'pen', 102:'' 103:'book' 104:'paper' }
{ 101:'Writing', 102:'stuff', 103:'school', 104:'office' }
{ 101:'stuff', 102:'stuff', 103:'', 104:'' }
pandasand then transforming it into adictionaryDataFrame to dict?