This solution demonstrates various filtering and transformation operations on an Indian customer dataset using pandas.
import pandas as pd
# Load Excel File
df = pd.read_excel("indian_customer_data.xlsx")
# Convert registration date to datetime
df['Date of Registration'] = pd.to_datetime(df['Date of Registration'], errors='coerce')
# Customers aged 30 and above
age_30_above = df[df['Age'] >= 30]
# Customers from Tamil Nadu
from_tamil_nadu = df[df['State'].str.lower() == 'tamil nadu']
# Female customers in Delhi
female_in_delhi = df[(df['Gender'].str.lower() == 'female') & (df['State'].str.lower() == 'delhi')]
# Customers registered after 1st Jan 2023
registered_after_2023 = df[df['Date of Registration'] > '2023-01-01']
# Names starting with 'D'
starts_with_d = df[df['Full Name'].str.startswith('D')]
# Emails ending with @yahoo.com
email_yahoo = df[df['Email'].str.endswith('@yahoo.com')]
# Address containing 'Nagar'
address_contains_nagar = df[df['Address'].str.contains('Nagar', case=False, na=False)]
# Aadhaar middle four digits = 5405
aadhaar_middle_5405 = df[df['Aadhaar'].str[5:9] == '5405']
# Add Initial and Registration Year
df['Initial'] = df['Full Name'].str[0]
df['Registration Year'] = df['Date of Registration'].dt.year
# Customers who registered in 2024
registered_2024 = df[df['Registration Year'] == 2024]
str.startswith, str.contains, and slicing for pattern matching.Initial: First character from the Full Name.Registration Year: Extracted from the date field.