I have a csv file like this:
'3', '8948', 'f678'
'3', '5654', 'f644'
'6', '5567', 'g3335'
'9', '4467', 'g3356'
'9', '7666', 'h4433'
The CSV holds various records. The first column represents an ID field.
I have looped through the CSV file and added the rows to a list.
I have then used that list to make a JSON file. Which looks like this:
[
[
"3",
"8948",
"f678"
],
[
"3",
"5654",
"f644"
],
[
"6",
"5567",
"g3335"
]
...
But as I understand it, I wont be able to read from this JSON and perform tasks on it? From what I can see I need it to be a dictionary, but how can I make a dictionary from my CSV, especially since the ID field is repeated and wont be unique. The only other option is to just use a row number, if this is correct - how do I create a dictionary from my CSV with a row number?
[
and]
at the start and end of each line? If not, then you can just read it using panda and provide the column names, likedf = pd.read_csv(filename, sep=',', names=['field1', 'field2', 'field3'], header=None)
and then usedf.to_json()
- BdR