4 Ways to export Data from Python
Text File
with open('data.txt', 'w') as file:
for item in data:
file.write(str(item) + '\n')CSV File
import csvGet Tech Talk With Alex’s stories in your inbox
Join Medium for free to get updates from this writer.
xtiwith open('data.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)
Excel File
import pandas as pd
df = pd.DataFrame(data)
df.to_excel('data.xlsx', index=False)JSON
import json
with open('data.json', 'w') as file:
json.dump(data, file)








