import pandas as pd
Run to view results
# We will store the orders table csv data in a variable
# Tabs are used as the separating character in this file
file_path = '/work/mtcars.csv'
file = pd.read_csv(file_path)
Run to view results
# Use the head method to investigate the first row of data
file.head()
Run to view results
# Create a dataframe to view the column names and data types
df = pd.DataFrame(file)
df.head()
Run to view results
# Use the shape attribute to determine the amount of rows and columns total
df.shape
Run to view results
# Use the .columns property to list out the column names
# Use the .index.name property to identify the index
print(f"{df.columns}")
print(f"{df.index.name}")
Run to view results
# Provide a dictionary to the rename method to rename any columns
# The inplace flag determines whether to modify the original dataframe
df.rename(columns = {'mpg': "Miles Per Gallon", 'cyl': 'cylinders'}, inplace = True)
Run to view results
# Explore columns with column attributes and methods
df.describe
Run to view results
# Import the products.csv dataset and explore the following questions:
link="https://raw.githubusercontent.com/austinlasseter/hosting_some_files/main/pandas_files/products.csv"
products = pd.read_csv(link)
Run to view results
# A. What are the columns and index: do they suggest any relationship to other tables?
print(products.columns)
print(products.index.name)
Run to view results
# B. How many rows of data are there?
print(f" This dataframe has {products.shape[1]} rows of data")
Run to view results
# C. What are the types of each column?
products.dtypes
Run to view results
# Let's return to the orders dataset for the rest of the challenges
# Use boolean filtering and DataFrame/DataSeries methods to solve the following challanges:
link="https://raw.githubusercontent.com/austinlasseter/hosting_some_files/main/pandas_files/orders.csv"
orders = pd.read_csv(link)
Run to view results
print(f' Mean: {orders[orders["ship_mode"] == "Second Class"]["profit"].mean()}')
Run to view results
# C. Which products were ordered on the busiest day?
orders["order_date"].value_counts().head()
Run to view results
# A. Who is the top customer?
Run to view results
# B. What are the three top orders purchased by top customer?
Run to view results