Python Cheatsheet For Data Scientists
Python Cheatsheet For Data Scientists
x = 10 # int
y = 3.14 # float
name = "AI" # str
flag = True # bool
lst = [1, 2, 3]
tpl = (1, 2, 3)
dct = {"a": 1, "b": 2}
st = {1, 2, 3}
NumPy
import numpy as np
a = np.array([1, 2, 3])
b = np.zeros((2, 3))
c = np.ones(5)
d = np.eye(3)
e = np.linspace(0, 1, 5)
Pandas
import pandas as pd
df = pd.read_csv("data.csv")
df.head(), df.info(), df.describe()
df["col"], df[["col1", "col2"]]
df[df["col"] > 5]
df.groupby("group_col").mean()
df.isnull().sum()
df.fillna(0), df.dropna()
plt.plot([1,2,3], [4,5,6])
plt.hist([1,2,2,3])
plt.show()
sns.boxplot(x="col", data=df)
sns.heatmap(df.corr(), annot=True)
X = df[["feature1", "feature2"]]
y = df["target"]
preds = model.predict(X_test)
mse = mean_squared_error(y_test, preds)
pd.get_dummies(df["category"])