0

I have an iris dataset, and I need to use 1. the first 50 rows, 2. the 50-100 row 3. the 100-150 row. How can I do that? The first 50 rows are pretty simple to get, I just use iris.head(50), how about the other 2? The whole code looks like this:

import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt

iris_data = load_iris()

iris = pd.DataFrame(data=np.c_[iris_data['data'], iris_data['target']],
                    columns=iris_data['feature_names'] + ['species'])


setosa = iris.head(50)
del setosa ['species']

print(setosa.columns)
plt.boxplot(setosa, vert=True)
plt.title(f"Features of the setosa")
plt.xticks([1, 2, 3, 4], ['sepal length', 'sepal width', 'petal length', 'petal width'])
plt.xlabel('Features')
plt.ylabel("Length/Width (cm)")
plt.show()

I expect to get data from the 50th row to 100th row,and from 100th row to 150th row

Katono
  • 28
  • 4
  • 1
    Does this answer your question? [Slice Pandas DataFrame by Row](https://stackoverflow.com/questions/11881165/slice-pandas-dataframe-by-row) – Rabinzel Nov 18 '22 at 15:36

0 Answers0