Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a list of lists of pure data like this
a=[[1,2,3], [4,5,6], [7,8,9]]
How can I write a into a CSV file with each list in a column like this?
a
1 4 7 2 5 8 3 6 9
a=[[1,2,3],[4,5,6],[7,8,9]];
df = pd.DataFrame(a).T;
df.to_csv("output.csv",index=False,header=False)
Use:
import csv with open('output.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile) writer.writerows(list(zip(*l)))
Add a comment
Try this:
import csv with open('output.csv', 'w', newline='') as f: writer = csv.writer(f, delimiter=' ') writer.writerows(a)
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
a=[[1,2,3],[4,5,6],[7,8,9]];df = pd.DataFrame(a).T;df.to_csv("output.csv",index=False,header=False)