cc88
cc88

Reputation: 178

Subsetting in python using multiple row ranges

I am trying to plot a scatterplot using only data from rows 0 to 34 and 80 to 1001. I have tried the following code but it doesn't work:

plt.scatter(df.iloc[[0:34, 80:101], 1], df.iloc[[0:34, 80:101], 0])

I have also tried doing it conditional, using index numbers, but I cannot refer to the index.

What is the way to do this?

Upvotes: 1

Views: 88

Answers (1)

Mayank Porwal
Mayank Porwal

Reputation: 34086

You can use numpy.r_ for selecting multiple ranges at once:

Try this:

import numpy as np
plt.scatter(df.iloc[np.r_[0:34, 80:101], 1], df.iloc[np.r_[0:34, 80:101], 0])

Upvotes: 1

Related Questions