import pandas as pd
source_url="https://raw.githubusercontent.com/austinlasseter/hosting_some_files/main/pandas_files/Production.Product.csv"
Run to view results
# read the dataset as a DataFrame into a variable named 'prod_df'
prod_df = pd.read_csv(source_url, sep = '\t')
# if get ParserError: Error tokenizing data. C error: Expected 1 fields in line 211, saw 2
# ... might need to use seperator
Run to view results
# your answer here
prod_df.head(4)
Run to view results
# your answer here
prod_df.shape[0]
Run to view results
# your answer here
print(int(prod_df.shape[1]))
Run to view results
# your answer here
prod_df['ProductLine'].nunique()
Run to view results
# your answer here
list(prod_df['ProductLine'].unique())
Run to view results
# your answer here
# No, because the unique function included NaN's (Not a Number)
Run to view results
# your answer here
list(prod_df['ProductLine'].unique())
len(list(prod_df['ProductLine'].unique())[1])
Run to view results
# your answer here
#2 but expected 1
# there's a trailing whitespace
# arg
len(list(prod_df['ProductLine'].unique())[1].strip())
Run to view results
# your answer here
prod_df[prod_df['ProductLine']=='R '].shape[0]
Run to view results
# your answer here
prod_df[(prod_df['ProductLine']=='M ') & (prod_df['Style']=='W ')].shape[0]
#ProductLine - R = Road, M = Mountain, T = Touring, S = Standard
#Style - W = Womens, M = Mens, U = Universal
Run to view results
Run to view results
# your answer here
# create boolean index for women's and mountain
w_m = (prod_df['ProductLine']=='M ') & (prod_df['Style']=='W ')
w_m.head()
Run to view results
# create boolean index for silver
s = (prod_df['Color']=='Silver')
s.head()
Run to view results
# combine those indices
combo = w_m | s
combo.head()
Run to view results
# create placeholders for column name lists and dictionaries
cols = ['Name', 'ListPrice']
new_cols = {'Name': 'NewName'}
Run to view results
# sort values and display
# Kathy way
prod_df[combo][['Name', 'ListPrice']].sort_values(by='ListPrice', ascending=False).head(3)
Run to view results
Run to view results