J
J
jddxecoc2021-08-31 04:07:22
Python
jddxecoc, 2021-08-31 04:07:22

How to split a csv file by columns in Python?

There is a long CSV file (1'000'000+ lines). Column names are missing. How to output certain columns from it to other files as efficiently as possible?
Example:

CSV 4 columns
150000,2016-01-01,Chris Riley,[email protected]
150000,2016-01-01,Harold Campbell,[email protected]
150000,2016-01-01,Jessica Nichols,[email protected]
150000,2016-01-01,Catherine Brown,[email protected]
150000,2016-01-01,Kelly Frazier,[email protected]
150000,2016-01-01,Dennis Howard,[email protected]

We select, for example, 3 and 4 columns. After the program has run, two files should be obtained. In one list, all data from 3 columns, in the other list, all data from 4 columns.
File 1
Chris Riley
Harold Campbell
Jessica Nichols
Catherine Brown
Kelly Frazier
Dennis Howard

File 2
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HemulGM, 2021-08-31
@jddxecoc

THIS IS THE MAXIMUM TRIVIAL TASK. AT LEAST LITTLE TRY TO SOLVE IT YOURSELF
https://docs.python.org/3/library/csv.html
https://code.tutsplus.com/en/tutorials/how-to-read...
https: //python-scripts.com/import-csv-python
https://all-python.ru/osnovy/csv.html
4 THE FIRST LINKS IN GOOGLE SOLVE YOUR "PROBLEM"

R
Ruslan., 2021-08-31
@LaRN

If the task is one-time, then without programming, you can simply open the source file through, for example, excel and simply accumulate the columns from the source file into new ones and then save as csv with the "," separator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question