■ Python Libraries Cheat Sheet
NumPy — Numerical Python library for arrays and math operations.
• Import: import numpy as np
• Create array: np.array([1,2,3])
• Zeros/ones: np.zeros((2,3)), np.ones(4)
• Random: np.random.rand(3)
• Mean/Median/Std: np.mean(arr), np.median(arr), np.std(arr)
• Reshape: arr.reshape(2,3)
• Indexing/Slicing: arr[0], arr[1:3]
• Math ops: np.add(a,b), np.dot(a,b)
Pandas — Data analysis and manipulation library.
• Import: import pandas as pd
• Read CSV: pd.read_csv('file.csv')
• DataFrame creation: pd.DataFrame(data)
• View data: df.head(), df.info(), df.describe()
• Select columns: df['col'], df[['a','b']]
• Filter rows: df[df['col'] > 10]
• Group by: df.groupby('col').mean()
• Handle missing: df.dropna(), df.fillna(0)
• Export CSV: df.to_csv('out.csv')
Matplotlib — Visualization library.
• Import: import matplotlib.pyplot as plt
• Line plot: plt.plot(x, y)
• Scatter: plt.scatter(x, y)
• Bar chart: plt.bar(x, y)
• Histogram: plt.hist(data, bins=10)
• Labels: plt.xlabel('X'), plt.ylabel('Y')
• Title: plt.title('My Chart')
• Show: plt.show()
• Save figure: plt.savefig('fig.png')
SciPy — Scientific computing built on NumPy.
• Import: from scipy import stats, integrate, optimize
• Stats: stats.norm.mean()
• Integration: integrate.quad(func, 0, 1)
• Optimization: optimize.minimize(func, x0)
Seaborn — High-level statistical visualization.
• Import: import seaborn as sns
• Plot: sns.barplot(x, y, data=df)
• Heatmap: sns.heatmap(df.corr(), annot=True)
• Pairplot: sns.pairplot(df)
• Style: sns.set_style('darkgrid')