Task: I'm importing a .CSV files as a pandas dataframes. I'm writing one column of that dataframe to a .txt file. Importantly, each row of the column must only be written as one row in the text file, never more (hence stripping /n)!
I have a very large dataframe (2 million rows), and this loop is naturally very slow given the I/O overhead. Any suggestions for improvements?
for i in tqdm(data['column'].head(500)): f = open("Questions.txt","a", newline="\n",encoding='utf-8') f.write(i.strip("/n")) f.write("\n") f.close()