1

Lets say I have created a pandas dataframe

df = pd.DataFrame(dict)

now I'm running a selection on it like this

print(df.iloc[2])

the Result is some subset of the dataframe.

The question is: how can I export/ save this Result to a CSV file?

merci in advance

A

aerioeus
  • 952
  • 1
  • 8
  • 28

1 Answers1

3

You can use the to_csv function on the subset of df.

df.iloc[2].to_csv('path/myfile.csv')
Wouter
  • 2,284
  • 3
  • 13
  • 1
    @BarbarosÖzhan Thanks for the comment. The behaviour of the parameters after `iloc` with one row is a bit different. `index=False` actually removes the column names and `headers=False` removes the index. I'll leave it to OP to decide how he wants it exactly. – Wouter Jan 27 '21 at 11:24
  • thanks , @wouter, that works for me. the `index = false` is not needed since I want the index names saved as well. Thanks for the idea anyway. :thumbsup – aerioeus Jan 27 '21 at 11:38