Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
I have a dataframe that contains 1000 records. But I need to save only 100 records in the file. It should be starting at 100. Could you please suggest a solution.

1 Answer

0 votes
by (36.8k points)

Use the below code:

# Creating a dataframe with 1000 rows

df=pd.DataFrame()

df=df.append(["x"]*1000)

# Loop

i=0

while i <len(df)-1:

   df.iloc[i:i+100,:].to_excel("output_{0}_{1}.xlsx".format(i,i+100),index=False)

   i+=100

Improve your knowledge in data science from scratch using Data science online courses 

Browse Categories

...