I want to read each column of a csv file and do some modification before storing them into table.
I have a csv files as :
"1";"testOne";"ValueOne"
"2";"testTwo";"ValueTwo"
"3";"testThree";"ValueThree"
Here I want to read the first value "1" and then store it somewhere in a varaible and do something with this value, and similary with the others. However currently I can read the whole file, but could not find the way to access individual columns in a row.
Thank you.
Use pandas. read_csv() to read a specific column from a CSV file. To read a CSV file, call pd. read_csv(file_name, usecols=cols_list) with file_name as the name of the CSV file, delimiter as the delimiter, and cols_list as the list of specific columns to read from the CSV file.
Steps. Make a list of columns that have to be extracted. Use read_csv() method to extract the csv file into data frame. Print the exracted data.
Python has a built-in csv module.
import csv
with open('some.csv', 'rb') as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
print row[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With