Lorenzo Palacio
Lorenzo Palacio

Reputation: 45

How do I convert one column of a csv file to a txt file in Python?

I have a specific column in a csv file and I want to write each row of that column as a newline in the same txt file. I'm using Panda if that helps. I can't quite figure out how to iterate over the rows of one specific column.

Upvotes: 1

Views: 2294

Answers (1)

Maxim Skoryk
Maxim Skoryk

Reputation: 472

This should work:

dataframe[colname].to_csv('filepath.txt', sep="\n", index=False)

add header = False if you don't need the column name in that .txt file

Upvotes: 1

Related Questions