Skip to content

Nandini-2325/Python-DataFrame-Basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Python-DataFrame-Basics

🚗 Pandas Vehicle Dataset Analysis

This repository contains exercises using Pandas to explore and analyze a vehicle dataset (mpg.csv). The goal is to practice data exploration, Boolean operations, arithmetic calculations, and column manipulation in Python.


📌 Summary of Tasks

  1. Data Exploration

    • Imported the CSV dataset into a Pandas DataFrame.
    • Explored the data using .head(), .tail(), .describe(), .shape(), .mean(), .sum(), .value_counts(), .max(), .min(), len(), and .median().
    • Sorted values to inspect specific columns.
  2. Creating New Columns

    • Created a Boolean column is_automatic indicating if a vehicle has an automatic transmission.
    • Added a calculated column fuel_economy as a weighted average:
      fuel_economy = (city_mpg * 0.55) + (highway_mpg * 0.45).
  3. Analysis Using Boolean Masking

    • Used is_automatic to count the number of automatic vehicles.
    • Determined percentage of subcompact vehicles.
    • Filtered vehicles with fuel_economy above the median using Boolean masking.

⚡ Skills Practiced

  • Importing and inspecting CSV datasets with Pandas.
  • Exploring data with descriptive statistics and summary functions.
  • Creating and manipulating new columns using arithmetic operations.
  • Filtering and analyzing data using Boolean masking.
  • Calculating percentages and weighted averages.
  • Summarizing insights from the dataset effectively.

This exercise reinforces foundational Pandas skills for real-world data analysis and prepares for more advanced data manipulation tasks.


1️⃣ Importing the CSV and Exploring the Dataset

import pandas as pd

Load the dataset

mpg = pd.read_csv('mpg.csv')

Display first few rows

mpg.head()

image

Task: Use the is_automatic column to find how many vehicles are automatic.

Sum the Boolean column to count automatic vehicles

mpg['is_automatic'].sum()

image

Task: Determine what percentage of vehicles are subcompacts.

Count subcompact vehicles and calculate percentage

subcompact_percentage = mpg[mpg["class"] == "subcompact"]["class"].count() / len(mpg) * 100 subcompact_percentage image

Task: Add a fuel_economy column as a weighted average of city and highway MPG (55% city, 45% highway).

Calculate weighted fuel economy

mpg['fuel_economy'] = mpg['cty'] * 0.55 + mpg['hwy'] * 0.45

Display first few rows to verify

mpg.head() image

Task: Use Boolean masking to find vehicles with fuel_economy above the median.

Filter vehicles with fuel_economy above the median

high_fe_vehicles = mpg[mpg.fuel_economy > mpg.fuel_economy.median()]

Display first few rows

high_fe_vehicles.head() image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published