1

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.

3
  • 1
    Non-Python answer: cut -d';' -f<column-number>. ;-) Commented Feb 18, 2022 at 17:03
  • Do you want to append a column data to same csv file from which you are reading data? Or to a new txt file? Commented Feb 18, 2022 at 17:16
  • Will you please edit your question and include a small sample input, and how "each row of that column as a newline" looks "in the same txt file"? thanks! :) Commented Feb 19, 2022 at 0:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.