Start with Python and Pandas – Part 3

Hello Friends! I’ll be continuing from previous article about Python and we’ll learn more about Python.

List unique values in a DataFrame column

df['Column Name'].unique()

Quick overview of DataFrame

df.describe()
df.info()

Find data type

filteredColumns = empDfObj.dtypes[empDfObj.dtypes == np.object]
df.drop(columns = filteredColumns)
df.dtypes

Find unique

abc = df.columns[df.nunique() <= 1]
drop unique columns
df.drop(columns = abc)

Drop columns in which more than 10% of values are missing:

df.dropna(thresh=len(df)*0.9, axis='columns')

View a range of rows of a dataframe

df.iloc[2531:2580]

Remove / delete rows where a condition or conditions are met

df = df.drop(df[df.score < 50].index)

Grab DataFrame rows where specific column is null/notnull

newdf = df[df['column'].isnull()]

For more quick refresh of pandas –

https://gist.github.com/fomightez/ef57387b5d23106fabd4e02dab6819b4


One comment

Leave a Reply

Your email address will not be published. Required fields are marked *