Skip to content
Advertisement

How to complete a CSV file with data from a Python dictionary in progress

I would like to know how to save data from my python dictionary (being created) to a CSV file at the same time (i.e. as soon as a python dictionary line is created it should be sent directly to the CSV file)

I’m using the following code :

JavaScript

I would like to obtain a fisrt column for text, topic and tags Do you have an idea how to change my 2 steps code (=dictionary conception then convert it to CSV) to a dynamic one ?

Advertisement

Answer

I reshuffled your code a bit: 1. I moved data.append to the try block. Otherwise the data would not be appended. 2. I moved df.to_csv to the try block as well, which makes that the csv will be re-saved every time new data is appended to the list.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement