Python 資料分析入門
Python 是資料分析領域的首選語言,擁有豐富的生態系。
NumPy 基礎
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr.mean()) # 3.0
print(arr.std()) # 1.414
Pandas 資料處理
import pandas as pd
df = pd.read_csv('data.csv')
print(df.head())
print(df.describe())
filtered = df[df['age'] > 25]
grouped = df.groupby('category')['price'].mean()
資料視覺化
import matplotlib.pyplot as plt
df.groupby('category')['sales'].sum().plot(kind='bar')
plt.title('Sales by Category')
plt.show()
實作建議
- 使用
df.info()快速了解資料概況 - 用
df.isnull().sum()檢查缺失值 - 善用
pivot_table進行多維度分析