All Courses

If i have a data frame of 100 rows, then how can i save a csv file of 21 row to 45 row ?

By Pp5344229@gmail.com, a month ago
  • Bookmark
0

How to save a CSV file from the 21st row to the 45th row If I have a data frame of 100 rows

Pandas
Csv file
2 Answers
0
Hitendradixit18@gmail.com

use head and tail

0
Goutamp777

Here is an example of how you can save a csv file from row 21 to 45 of a data frame in Python:               import pandas as pd


# Load your data frame

df = pd.read_csv('your_data_frame.csv')


# Select rows 21 to 45

df = df[20:45]


# Save the new data frame as a csv file

df.to_csv('subset_of_your_data_frame.csv', index=False)                                                               .

Note that the index starts from 0, so the 21st row is indexed as 20 and the 45th row is indexed as 44

Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More