0
import pandas as pd
pd.__version__
df = pd.read_csv('myfile.csv', usecols=[0,3,4,5,9])
print (df)

I only want to return these specific columns from my csv file and write it into a new csv file?

How can I do this

so far i can read the data!! but not sure how to write it

ABSOLUTE PYTHON BEGGINER ALERT

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Girl007
  • 165
  • 1
  • 13

1 Answers1

1

based on your input, i assume you are trying to achieve something like this ?

#import library
import pandas as pd
pd.__version__

# read the csv with all columns
df = pd.read_csv('myfile.csv')
print (df)

# create csv with filtered columns
filter_cols = ["0","3","4","5","9"]
df.to_csv('output.csv', columns = filter_cols)
Samtech
  • 339
  • 5
  • 18