user3429227
user3429227

Reputation:

Save pandas output into new file

I'd like to save the output I get from this piece of code:

import pandas as pd
df = pd.read_csv("inputfile.csv",sep=";",decimal=",", nrows=100)
print (df)

to a new file that then only includes the 100 rows from the input-file?

I tried something with 'w', but that didn't really work.

Thanks for your help!

Upvotes: 0

Views: 3187

Answers (2)

ode2k
ode2k

Reputation: 2723

You will need to use the pandas.Dataframe.to_csv function:

 df.to_csv("outputfile.csv", sep=";", decimal=",")

Upvotes: 1

gehbiszumeis
gehbiszumeis

Reputation: 3711

pandas can also write to *.csv files:

# Write to file with same separator/decimal setting as in your input file
df.to_csv('my_csv.csv', sep=';', decimal=',')

Upvotes: 1

Related Questions