I'm using following script to
- Apply a function to a column in each row of a DataFrame
- Write the returns from that function into two new columns of a DataFrame
- Continuously write the DataFrame into a *.csv
I like to learn whether there's a better way to run the following computation:
df = a DataFrame with 500 rows, 20 columns
for index, row in df.iterrows():
df.loc[index, 'words'], df.loc[index, 'count'] = transcribe(df.loc[index, 'text'])
df.to_csv('out.csv', encoding='utf-8', index=False)
Currently, the script each time (for each row) outputs the full df dataframe as *.csv, including the added values for the computed rows "words" and "counts" until then. I like to know, whether it would also be possible to just write line by line complete, i.e. to only output those lines in the csv that are complete.
Thanks!