drop columns and rows in one line in pandas

I want to drop a range of rows and columns of a dataframe, I did it as follow:

df.drop(df.columns[3:], axis=1, inplace=True)
df.drop(df.index[3:], axis=0, inplace=True)

Can I do the two processes in one method instead of two? Or is there any more sufficient way to accomplish this?

Topic methods pandas

Category Data Science


Why don't you do this:

df = df.iloc[:3, :3]

It returns the same thing as your code.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.