Dan csv file with such data:

Col1; col2; col3; col4; col5 1;2;3;4;5 12;13;14;15;16 31;32;33;34;35 

It is necessary in Python to make a new csv file with values ​​only from the first column:

 1 12 31 
  • And what have you got? - 0xdb

2 answers 2

 import csv filepath = r"in.csv" f = open("out.csv", "w") with open(filepath, "r", newline="") as file: for row in file: a = row.split(';') f.write(a[0] + '; \n' ) f.close() 
  • Thank you very much, everything works! - PyLam

You can use the Pandas module:

 import pandas as pd (pd.read_csv(r'/path/to/input.csv', usecols=[0], sep=';', skipinitialspace=True) .to_csv(r'/path/to/output.csv', sep=';', header=False, index=False)) 

Result:

 1 12 31 
  • one
    thank you very much, everything works -) - PyLam