Write a list of lists into csv in Python [duplicate]

2024/11/15 13:28:21

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?

1 4 7 
2 5 8
3 6 9
Answer

Use:

import csv
with open('output.csv', 'w', newline='') as csvfile:writer = csv.writer(csvfile)writer.writerows(list(zip(*l)))
https://en.xdnf.cn/q/120442.html

Related Q&A

Upper limit of points pyplot

Just being a curious George here. But Im handling 279 million data points (x,y) and am wondering if pyplot can scatter such a number?Thanks.

how to delete the u and before the of database table display by python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

python list permutations [duplicate]

This question already has answers here:Closed 12 years ago.Possible Duplicate:How to generate all permutations of a list in Python I am given a list [1,2,3] and the task is to create all the possible …

Repeating Characters in the Middle of a String

Here is the problem I am trying to solve but having trouble solving:Define a function called repeat_middle which receives as parameter one string (with at least one character), and it should return a n…

Remove a big list of of special characters [duplicate]

This question already has answers here:Remove specific characters from a string in Python(27 answers)Closed 5 years ago.I want to remove each of the following special characters from my documents: symb…

How to change a html page from flask to Django [duplicate]

This question already has an answer here:How to specify URLs in Django templates?(1 answer)Closed 7 years ago.I am working on an app that requires changing a flask template to that of Django.How to ch…

How to get the text of Checkbuttons?

Checkbuttons gets generated dynamically and they are getting text from a python list. I need a logic for capturing selected checkbuttons text . As per my research everywhere they are returning the stat…

Working out an equation

Im trying to solve a differential equation numerically, and am writing an equation that will give me an array of the solution to each time point.import numpy as np import matplotlib.pylab as pltpi=np.p…

combine rows and add up value in dataframe

I got a dataframe(named table) with 6 columns labeled as [price1,price2,price3,time,type,volume]for type, I got Q and T, arranged like:QTQTTQNow I want to combine the rows with consecutive T and add up…

How to access a part of an element from a list?

import cv2 import os import glob import pandas as pd from pylibdmtx import pylibdmtx import xlsxwriter# co de for scanningimg_dir = "C:\\images" # Enter Directory of all images data_path = os…