Skip to content

Instantly share code, notes, and snippets.

@karanjagota karanjagota/pandas_subset.py Secret
Created Jul 5, 2019

Embed
What would you like to do?
gist for my medium blogs ..
# -----------xxxxxxxxxxxxxxxx-----------------
# Q1. Extract only those rows where column_name: 'mpg' is greater than 30 .
df[df['mpg']>30] # or
df.loc[df['mpg']>30]
# ------------xxxxxxxxxxxxx--------------------
# Q2. Extract only those rows where column_name: 'origin' is equal to 'Asia'
df.loc[df['origin']=='Asia']
# -------------------xxxxxxxxxxxxx------------------
# Q3. Select only top 20 rows of the data/dataframe
df.iloc[0:20,]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.