Reputation: 147
I am confused on how to go about parsing an array list from a .csv file. The .csv file gives information on a daily basis, in this format:
{
"a" : 1,
"b" : 3,
"d" : 10
},
The open bracket shows the new day of data, and the closing bracket followed by the comma ends the data (I have no way of changing how the .csv is generated). There are about 400 days worth of data, and each day has the same list items (a,b, and d). How would I go about parsing the .csv data into a readable list format in python? I would post example code, but I have no idea where to even start with this.
Thanks in advance!
Upvotes: 0
Views: 381
Reputation: 3081
for parsing csv
import csv
a = ["1,2,3","4,5,6"] # or a = "1,2,3\n4,5,6".split('\n')
x = csv.reader(a)
print(list(x))
>>> [['1', '2', '3'], ['4', '5', '6']]
Upvotes: 1
Reputation: 159995
Your CSV file is almost certainly JSON. If it is, then Python has a json
library you can import and use:
import json
with open('/path/to/your/file.csv', 'r') as file
data = json.load(file)
# do things with data here
Upvotes: 2