Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
863e2ef
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
686419f
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
6e49a0a
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
e985855
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
dfe9e5a
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
bd3b6a0
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
ef97302
完成 M2 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
c29feba
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
916f754
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
baad50f
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
6b1b264
完成作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
a9094b8
完成作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
9d6dad2
完成作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
05f889b
完成作業 - 李舜權 - AIPE03
Mas-000 May 3, 2026
d646c1b
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
958caf4
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
df8c1e8
Update m2_pandas_cleaning.py
Mas-000 May 4, 2026
1dc8824
Update m3_pandas_advanced.py
Mas-000 May 4, 2026
2c34d85
Update m3_pandas_advanced.py
Mas-000 May 4, 2026
16029fd
Update m4_timeseries.py
Mas-000 May 4, 2026
62e93fb
Update m4_timeseries.py
Mas-000 May 4, 2026
22c8d89
Update m5_visualization.py
Mas-000 May 4, 2026
42c9902
Update m6_plotly_capstone.py
Mas-000 May 4, 2026
5467374
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
f1479b5
完成 M1 作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
499d5c6
完成作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
a7d2f27
完成作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
c4cc1ff
完成作業 - 李舜權 - AIPE03
Mas-000 May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__/
*.pyc
.pytest_cache/
.pytest_results.json
venv
45 changes: 26 additions & 19 deletions homework/m1_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,59 @@
# ============================================================
# 🟢 送分題(每題 10 分,共 30 分)
# ============================================================

def green_mean():
"""建立 [10, 20, 30, 40, 50],回傳所有元素的平均值 (float)"""
# TODO: 你的程式碼
pass

arr = np.array([10, 20, 30, 40, 50]).mean()
print(arr)
return arr

def green_double():
"""建立 [10, 20, 30, 40, 50],回傳所有元素乘以 2 的 ndarray"""
# TODO: 你的程式碼
pass
arr = np.array([10, 20, 30, 40, 50])
arr = arr*2
return arr



def green_filter():
"""建立 [10, 20, 30, 40, 50],回傳大於 25 的元素 (ndarray)"""
# TODO: 你的程式碼
pass
arr = np.array([10, 20, 30, 40, 50])
arr = arr[arr>25]
return arr


# ============================================================
# 🟡 核心題(每題 15 分,共 45 分)
# 以下函式會接收從 products.csv 讀出的 prices, stocks 陣列
# ============================================================

# ---------- 載入 products.csv ----------
DATA_PATH = "datasets/ecommerce/products.csv"
prices = np.genfromtxt(DATA_PATH, delimiter=",", skip_header=1, usecols=3)
stocks = np.genfromtxt(DATA_PATH, delimiter=",", skip_header=1, usecols=4)

def yellow_expensive_count(prices):
"""回傳單價 > 1000 的商品數量 (int)"""
# TODO: 你的程式碼
pass

rrrr = len(prices[prices>1000])
return rrrr

def yellow_top3_stock_indices(stocks):
"""
回傳庫存最多的前 3 個商品的索引位置 (ndarray, 由大到小排)
提示:np.argsort
"""
# TODO: 你的程式碼
pass

GGGG = np.argsort(stocks)[::-1][:3]
return GGGG

def yellow_restock_cost(prices, stocks):
"""
單價 < 500 的商品,每種各進貨 50 個,回傳總花費 (float/int)
提示:布林遮罩 + .sum()
"""
# TODO: 你的程式碼
pass

rrrr = (prices[prices<500]*50).sum()

return rrrr

# ============================================================
# 🔴 挑戰題(25 分)
Expand All @@ -76,5 +82,6 @@ def red_double11_prices(prices, stocks):
回傳每個商品的雙 11 售價 (ndarray)
提示:np.where 可以巢狀使用
"""
# TODO: 你的程式碼
pass
new_prices = np.where(stocks>=100 ,prices * 0.7,np.where((stocks>=20)&(stocks<100),prices*0.9,prices))
print(new_prices)
return new_prices
42 changes: 23 additions & 19 deletions homework/m2_pandas_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,33 @@
"""
import pandas as pd


# ============================================================
# 🟢 送分題(每題 10 分,共 30 分)
# ============================================================

def green_read_csv():
"""
讀取 orders_raw.csv,回傳原始 DataFrame(不做任何清理)
提示:pd.read_csv()
提示:pd.read_csv(s)
"""
# TODO: 你的程式碼
pass
df = pd.read_csv('datasets/ecommerce/orders_raw.csv')
return df


def green_shape(df):
"""
回傳 DataFrame 的 (列數, 欄數) tuple
提示:df.shape
"""
# TODO: 你的程式碼
pass
return df.shape


def green_dtypes(df):
"""
回傳 DataFrame 的欄位型別 (Series)
提示:df.dtypes
"""
# TODO: 你的程式碼
pass

return df.dtypes

# ============================================================
# 🟡 核心題(每題 15 分,共 45 分)
Expand All @@ -51,9 +47,9 @@ def yellow_clean_columns(df):
回傳清理後的 DataFrame(不要修改原始 df)
提示:df.columns.str.strip().str.lower()
"""
# TODO: 你的程式碼
pass

new_df = df.copy()
new_df.columns = new_df.columns.str.strip().str.lower()
return new_df

def yellow_clean_amount(df):
"""
Expand All @@ -62,17 +58,19 @@ def yellow_clean_amount(df):
回傳清理後的 DataFrame(不要修改原始 df)
提示:.str.replace() + .astype(float)
"""
# TODO: 你的程式碼
pass

new_df = df.copy()
new_df['amount'] = new_df['amount'].str.replace('$','',regex=False).str.replace(',','',regex=False).astype(float)
return new_df

def yellow_drop_duplicates(df):
"""
移除完全重複的列,回傳去重後的 DataFrame
提示:df.drop_duplicates()
"""
# TODO: 你的程式碼
pass
new_df = df.copy()
new_df = new_df.drop_duplicates(subset=None, keep='first', inplace=False)
return new_df



# ============================================================
Expand All @@ -92,5 +90,11 @@ def red_clean_orders(path):
回傳:清理後的 DataFrame
提示:pd.to_datetime(errors='coerce')
"""
# TODO: 你的程式碼
pass
df = pd.read_csv(path)
df.columns = df.columns.str.strip().str.lower()
df['amount'] = df['amount'].str.replace('$','',regex=False).str.replace(',','',regex=False).astype(float)
df['order_date'] = pd.to_datetime(df['order_date'],errors='coerce')
df = df.dropna(subset= ['amount','order_date'])
df = df.drop_duplicates(subset=None, keep='first', inplace=False)
return df

71 changes: 53 additions & 18 deletions homework/m3_pandas_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,56 @@ def green_load_and_merge():
- 再 LEFT JOIN products.csv ON product_id
提示:pd.merge(how='left')
"""
# TODO: 你的程式碼
pass

path = "datasets/ecommerce/"

df_orders = pd.read_csv(path + "orders_clean.csv")
df_customers = pd.read_csv(path + "customers.csv")
df_products = pd.read_csv(path + "products.csv")

m1 = pd.merge(df_orders,df_customers,on='customer_id',how = 'left')
m2 = pd.merge(m1,df_products,on='product_id',how = 'left')

return m2




def green_row_count(df):
"""回傳 DataFrame 的列數 (int)"""
# TODO: 你的程式碼
pass

return len(df)

def green_column_list(df):
"""回傳 DataFrame 的所有欄位名稱 (list)"""
# TODO: 你的程式碼
pass

return df.columns.tolist()

# ============================================================
# 🟡 核心題(每題 15 分,共 45 分)
# ============================================================

# def yellow_top_category(df):
# """
# 哪個商品類別 (category) 的總營收最高?
# 回傳該類別名稱 (str)
# 提示:groupby('category')['amount'].sum()
# """
# # return df.groupby('category')['amount'].sum().idxmax()
# df = df.groupby('category')['amount'].sum().idxmax()
# print(df)
# return df
# print(green_load_and_merge())


def yellow_top_category(df):
"""
哪個商品類別 (category) 的總營收最高?
回傳該類別名稱 (str)
提示:groupby('category')['amount'].sum()
"""
# TODO: 你的程式碼
pass

category_totals = df.groupby('category')['amount'].sum().idxmax()

return category_totals




def yellow_gold_vip_stats(df):
Expand All @@ -59,8 +81,11 @@ def yellow_gold_vip_stats(df):
回傳 tuple: (訂單數 int, 總金額 float)
提示:df[df['vip_level'] == 'Gold']
"""
# TODO: 你的程式碼
pass

gold_df = df[df['vip_level'] == 'Gold']
order_count = len(gold_df)
total_amount = gold_df['amount'].sum()
return (int(order_count), float(total_amount))


def yellow_region_avg_amount(df):
Expand All @@ -69,8 +94,8 @@ def yellow_region_avg_amount(df):
回傳 Series(index=region, values=平均金額)
提示:groupby('region')['amount'].mean()
"""
# TODO: 你的程式碼
pass
return df.groupby('region')['amount'].mean()



# ============================================================
Expand All @@ -93,5 +118,15 @@ def red_rfm_top5(df):

提示:groupby('customer_id').agg(...)
"""
# TODO: 你的程式碼
pass

rrr = df.groupby(['customer_id','customer_name']).agg(
{'order_date':'max','order_id':'count','amount':'sum'}
).reset_index()
rrr.columns = ['customer_id','customer_name','R','F','M']
result = rrr.sort_values(by='M',ascending=False).head(5)
print(result)
return result




Loading
Loading