Click here to Skip to main content
15,507,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
import pandas as pd
import csv
csv_columns = ['quesion,,options,answer,src']

data = open("aug6m.csv")
readBytes = data.read()
data1 = eval(readBytes)
questions = []
csv_file = "Names.csv"
print("vgfhgf", data1[0])

for item in data1:

    try:
        with open(csv_file, 'w') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
            writer.writeheader()
        for data in item:
            writer.writerow(data)
    except IOError:
        print("I/O error")


What I have tried:

this is my python code and aug6m.csv file have dictionary data like
{'question': 'A petition has been launched requesting that which game be made into an official Olympic sport?', 'answers': ['Yu-Gi-Oh!', 'Dungeons and Dragons', 'Chess', Texas Hold'em poker], 'answerIndex': [0], 'image_url': 'https://cdn.riddle.com/embeds/v2/images/q_80,c_fill,w_960,h_540/892/892e4e3759aa101047700d12a383bde3.jpg'}{....}{....}
etc.. but i want to store like each key value separate
column for example question,option,answer,src
Posted
Updated 18-Aug-21 5:57am
v2
Comments
Richard MacCutchan 18-Aug-21 11:26am    
That does not look very much like valid csv; more like JSON.
Maciej Los 19-Aug-21 3:12am    
👍

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900