Hello I show you my problem’s :
I right that for convert my csv in Json. But the résult is not exactly what I Want .
main.py
import csv
filename ="forcebrute.csv"
# opening the file using "with"
# statement
with open(filename, 'r') as data:
for line in csv.DictReader(data):
print(line)
csv
name;price;profit
Action-1;20;5
Action-2;30;10
Action-3;50;15
Action-4;70;20
Action-5;60;17
result i have:
{'name;price;profit': 'Action-1;20;5'}
{'name;price;profit': 'Action-2;30;10'}
{'name;price;profit': 'Action-3;50;15'}
{'name;price;profit': 'Action-4;70;20'}
{'name;price;profit': 'Action-5;60;17'}
And I would like this result:
3
Answers
An easy approach would be using pandas, also quite fast with large csv files. It might need some tweaking but you get the point.
You will need to specify the column delimiter then you can use json.dumps() to give you the required output format
Output:
You will need to use
Dictreader
from thecsv
library to read the contents of the CSV file and then convert the contents to a list before usingjson.dumps
to turn the data into JSON.