I am trying to put a list of dictionaries in a csv format using the package csv. I am able to convert the list of dictionary in a csv file but I need the content to be written in a variable. Here is the code :
keys = dict_all_data[0].keys()
with open('all_data.csv', 'w') as output_file:
dict_writer = csv.DictWriter(output_file, keys, extrasaction='ignore')
dict_writer.writeheader()
dict_writer.writerows(dict_all_data)
In pandas, there is a simple way to put the csv content in a variable by not precising the name of the csv to write.
result = df_result.to_csv(index=False)
Is there a way to do this similarly with the package csv, please ?
Best regards.