Skip to main content

Command Palette

Search for a command to run...

Navigating Data with Pandas: Indexing and Selection πŸ—ΊοΈ

Published
β€’3 min read
Navigating Data with Pandas: Indexing and Selection πŸ—ΊοΈ
P

πŸ‘‹ Hello! I'm passionate about DevOps and have over 1+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!

SKILLS:

πŸ”Ή Languages & Runtimes: Python, Shell Scripting, HCL, YAML πŸ”Ή Cloud Technologies: AWS, Microsoft Azure, GCP πŸ”Ή Infrastructure Tools: Docker, Terraform, AWS CloudFormation πŸ”Ή Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps πŸ”Ή Web Development: HTML, CSS, Bootstrap, Python, SQL

Job & Responsibilities:

πŸš€ Improved development efficiency by implementing CI/CD pipelines, resulting in a 30% reduction in deployment time on the test server. πŸ”’ Strengthened deployment and testing reliability by utilizing Docker containers and optimizing Dockerfile, reducing development issues on the test server by 20%. βš™οΈ Automated S3 bucket log creation with Shell scripting, eliminating 100% of manual search and saving 2 hours per week. πŸ“… Scheduled EC2 instance start/stop using Lambda functions and Event Bridge, leading to a 25% decrease in infrastructure costs. πŸ”§ Utilized AWS, Linux, Python, Docker, Shell scripting, Terraform, Jenkins Pipelines, and automation to streamline workflows and improve overall system performance.

I'm very detail-oriented and possess strong written and verbal communication skills. As a high performer with a possibility mindset, I strive to solve problems using efficient approaches.

Let's Connect & Grow:

If you find my profile suitable for the role you are searching for, please feel free to reach out to me at sumanprasad9766@gmail.com.

Introduction to Data Indexing and Selection πŸ”

Data Indexing and Selection in Pandas are fundamental concepts that allow you to access, filter, and manipulate data within a DataFrame. Understanding these operations is crucial for effective data exploration and analysis.

Selecting Rows and Columns πŸš€

Pandas provides multiple ways to select specific rows and columns from a DataFrame.

Use Case: Selecting Columns

# Example
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}
df = pd.DataFrame(data)

# Select a single column
name_column = df['Name']

# Select multiple columns
subset = df[['Name', 'Age']]

# Display the selected columns
print(name_column)
print(subset)

Use Case: Selecting Rows

# Example
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}
df = pd.DataFrame(data)

# Select rows based on a condition
selected_rows = df[df['Age'] > 30]

# Display the selected rows
print(selected_rows)

Conditional Selection 🎯

Pandas allows you to perform conditional selection, enabling you to filter data based on specific criteria.

Use Case: Conditional Selection

# Example
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}
df = pd.DataFrame(data)

# Conditional selection based on age
selected_data = df[df['Age'] > 30]

# Display the selected data
print(selected_data)

Indexing with .loc and .iloc πŸ“

Pandas provides .loc and .iloc indexers for label-based and integer-location based indexing, respectively.

Use Case: Label-based Indexing

# Example
import pandas as pd

# Create a DataFrame with custom index
data = {'Value': [10, 20, 30, 40, 50]}
custom_index = ['a', 'b', 'c', 'd', 'e']
df = pd.DataFrame(data, index=custom_index)

# Select a specific row using label-based indexing
selected_row = df.loc['c']

# Display the selected row
print(selected_row)

Use Case: Integer-location Based Indexing

# Example
import pandas as pd

# Create a DataFrame
data = {'Value': [10, 20, 30, 40, 50]}
df = pd.DataFrame(data)

# Select a specific row using integer-location based indexing
selected_row = df.iloc[2]

# Display the selected row
print(selected_row)

Setting and Resetting Index πŸ”„

You can manipulate the DataFrame index using the .set_index() and .reset_index() methods.

Use Case: Setting Index

# Example
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}
df = pd.DataFrame(data)

# Set the 'Name' column as the index
df.set_index('Name', inplace=True)

# Display the DataFrame with the new index
print(df)

Use Case: Resetting Index

# Example
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}
df = pd.DataFrame(data)

# Reset the index to default integer index
df.reset_index(inplace=True)

# Display the DataFrame with the reset index
print(df)

Understanding Pandas indexing and selection mechanisms empowers you to efficiently navigate and manipulate data, enabling you to extract valuable insights from your datasets. πŸš€

More from this blog

D

DeployToCloud

405 posts

πŸ‘‹ Welcome to my Hashnode blog! I'm a DevOps Engineer with 2+ years of experience. Join ~5k followers and explore 320+ blogs on Python, AWS, Docker, Jenkins, Linux, and more. Let's connect & grow πŸš€