0

I have a list of lists like the following one:

[[5, 6], [10, 11], [14, 15]]

I want to output them as a csv file maybe using pandas to_csv in the following format:

Start End
5     6
10    11
14    15

How can I do this? I have an idea of flattening the list and then making every two elements as a comma-separated line of a CSV file. But I think it can be done more easily.

3
  • 1
    So you want comma-separated or tab-separated? Your question and output example don't match. Commented Feb 4, 2022 at 13:55
  • 1
    What have you tried so far? Commented Feb 4, 2022 at 13:55
  • @matszwecja Any one of them would work. That doesn't matter. Commented Feb 4, 2022 at 13:55

1 Answer 1

1

If you want to use pandas you can use:

data = pd.DataFrame(data_list, columns=["start","end"])
data.to_csv("myfile.csv")
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that was freaking easy. I don't know why I thought it in a complicated way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.