Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

Member-only story

Top 7 Most Common Pandas Features You Should Know

Konstantin Mogilevskii
Level Up Coding
Published in
3 min readSep 27, 2024

Pandas is one of the most powerful and popular Python libraries for data manipulation and analysis. Whether you’re cleaning, transforming, or analyzing datasets, Pandas offers a wealth of functions that simplify your workflow. Below, we explore seven of the most common and useful features that every data scientist and analyst should know.

1. DataFrame Creation

The DataFrame is the core data structure in Pandas. It’s a two-dimensional, size-mutable, and heterogeneous tabular data structure with labeled axes (rows and columns). You can create a DataFrame from various data structures like lists, dictionaries, and NumPy arrays.

import pandas as pd

# Creating a DataFrame from a dictionary
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Salary': [50000, 60000, 70000]
}
df = pd.DataFrame(data)
print(df)

Output:

Name  Age  Salary
0 Alice 25 50000
1 Bob 30 60000
2 Charlie 35 70000

2. Data Selection (loc and iloc)

Selecting data by label or position is fundamental when working with large datasets. Pandas provides two methods for accessing data from DataFrames: loc (label-based indexing) and iloc (integer-based indexing).

  • loc: Use for label-based indexing.
  • iloc: Use for positional indexing.
# Selecting by label
print(df.loc[0]) # First row based on label

# Selecting by position
print(df.iloc[1]) # Second row based on position

3. Filtering Data

Filtering allows you to create subsets of data based on conditions. You can filter rows using conditional statements.

# Filter rows where Age is greater than 30
filtered_df = df[df['Age'] > 30]
print(filtered_df)

Output:

Name  Age  Salary
2 Charlie 35 70000

4. Handling Missing Data

Missing data is a common issue in real-world datasets. Pandas provides methods like isna(), fillna(), and dropna() to handle missing values efficiently.

  • isna(): Detect missing values.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response