Mastering Pandas: DataFrame Attributes and Methods

ShehzifiedShehzified
4 min read

If you're diving into data analysis with Python, pandas is an essential library, and mastering its DataFrame is a must. This blog post serves as a quick-reference guide covering the most important DataFrame attributes and methods you'll need for data inspection, cleaning, transformation, and analysis.


๐Ÿ” DataFrame Attributes

Attributes give you quick insights into the structure and metadata of your DataFrame.

AttributeDescription
.shapeReturns a tuple of the DataFrame dimensions (rows, columns)
.dtypesData types of each column
.valuesNumpy array representation of the DataFrame
.columnsColumn labels
.indexRow index labels
.index.nameName of the index (can be set manually)
.columns.nameName of the columns axis
.sizeTotal number of elements (rows ร— columns)

โš™๏ธ Data Inspection Methods

Use these methods to understand the contents and structure of your data.

MethodDescription
.info()Summary of DataFrame: columns, data types, non-null values
.head(n)First n rows (default: 5)
.tail(n)Last n rows (default: 5)
.sample(n)Random n rows from the DataFrame

๐Ÿ“Š Aggregation & Summary Statistics

Quickly summarize numerical data in your DataFrame.

MethodDescription
.count()Count of non-null values (column-wise by default)
.min()Minimum values (all columns unless numeric_only=True)
.max()Maximum values
.sum()Sum of values
.mean()Mean of numeric values
.describe()Summary stats like count, mean, std, min, and quartiles

๐Ÿ› ๏ธ Data Cleaning & Manipulation

Essential methods to tidy and transform your data.

MethodDescription
.rename(columns={}, index={})Rename column or index labels (use inplace=True to apply directly)
.value_counts()Frequency count of unique rows (DataFrame) or values (Series)
.sort_values(by='', ascending=True)Sort by column(s)
.sort_index()Sort rows by index
.isnull() / .notnull()Detect missing values
.dropna()Drop rows or columns with missing data (customizable with how and subset)
.fillna() / .ffill() / .bfill()Fill missing values forward or backward
.duplicated()Detect duplicate rows (or based on subset of columns)
.drop_duplicates()keep = โ€˜firstโ€™ by default, drop duplicate rows (or based on subset of columns)
.drop(index=[], columns=[])Drop rows or columns explicitly
.rank()Rank data within each column

๐Ÿ”„ Index Management

Useful when dealing with hierarchical or multi-index data.

MethodDescription
.set_index(col)Make a column the index
.reset_index()Reset index to default (turn index into a column)

๐Ÿง  Custom Functions & Advanced Selection

Go beyond built-ins by applying your own logic.

MethodDescription
.apply(func)Apply function column-wise by default; use axis=1 for row-wise operations
.select_dtypes(include='number')Filter columns by data type
.nunique(dropna=True)Number of unique values in each column (excluding NaN by default)
.isin([])Check whether each element is in a given list
.copy()Create a deep copy of the DataFrame

โœ… Final Tips

  • These methods and attributes are the foundation of pandas workflows.

  • Combine them to filter, clean, and understand your data efficiently.

  • Use .apply() for custom logic and .describe() for quick numeric overviews.

Bookmark this guide and revisit it as you work on real-world datasets. Mastering these will level up your data analysis game significantly!


๐ŸŽ Bonus Resources: Dive Deeper with My GitHub Repo

If you're serious about mastering data analysis with Python, donโ€™t miss out on this curated GitHub repository:

๐Ÿ”— Python-Data-Analysis by ShehrazSarwar

๐Ÿ“Œ Whatโ€™s Inside?

  • โœ… Step-by-step Jupyter notebooks for every major Pandas and NumPy concept

  • ๐Ÿ“Š Real-world datasets with hands-on case studies

  • ๐Ÿงน In-depth data cleaning and preprocessing workflows

  • ๐Ÿ“ˆ Data exploration and visualization techniques using Matplotlib and Seaborn

  • ๐Ÿ” Practical insights generated using EDA (Exploratory Data Analysis)

๐Ÿ’ก Perfect for:
Beginners, students, and aspiring data analysts who want to build a strong foundation with Python and real datasets.

Bookmark it, fork it, and use it as your personal data analysis workbook!

Happy analyzing with pandas ๐Ÿš€

10
Subscribe to my newsletter

Read articles from Shehzified directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shehzified
Shehzified

I'm Shehraz Sarwar, a CS student at IUGC and Silver Medalist from FAST. I love blending code with creativity, exploring Python, Data Science, AI, and the real-world magic of math. With a strong base in Python and Data Analysis, along with C, C++, and Java, I tackle problems through hands-on projects. Beyond code, I dive into video editing, 3D art, and UI/UX design, fueling my journey to become a versatile Computer Scientist.