1/41
Looks like no tags are added yet.
x**2
x²
//
division (truncate to nearest integer)
.upper()
make all characters uppercase
.lower()
make all characters lowercase
.title()
capitalize first letter of every word
.capitalize()
capitalize the first letter of whole string, rest lowercase
.split()
split string into words separated by “ “
random.seed()
initialize random generator
random.randint(a, b)
random integer between a and b
random.choice()
random thing from a sequence
break
exit loop immediately
continue
skip the rest of the loop, retest condition to do loop again
pass
does nothing - useless
return
exit function and output something
.insert(i, a)
insert a into list at index i
.append(a)
add a to end of list
np.shape()
Dimensions of np array
np.ndim()
Number of dimensions of np array
np.dtype()
Data type of elements in np array
pd.DataFrame(data)
create pd data frame w data
pd.read_csv("abc.csv")
import abc.csv into pandas
pd.read_excel("abc.xlsx")
import abc.xlsx into pandas
df.head(n)
First n rows of dataframe
df.columns()
List of dataframe column names
df.to_csv("output.csv", index=False)
Export df as output.csv
df.to_excel("output.xlsx", index=False)
Export df as output.xlsx
df.to_csv("output.txt", sep = "\t", index=False)
Export df as output.txt file, separate columns by tabbing over
with pd.ExcelWriter("output.xlsx", engine = "openpyxl") as writer:
df.to_excel(writer, sheet_name = "Sheet1", index = False)
Export df to Sheet1 in output.xlsx
df[["Name", "Age"]]
df columns “Name” and “Age”
pd.merge(df1, df2, on="c1")
combine df1 and df2, using the same row when the column “c1” is equal
df[df["r1"] condition]
filter df based on when row “r1” follows condition
df.sort_values(by="r1")
sort df by row “r1”
df.sort_values(by="r1", ascending=False)
sort df by row “r1” in descending order
df.isnull()
Missing values in df
df.isnull().sum()
Number of missing values per column in df
df.dropna()
Remove rows of df with missing values
df.fillna(0)
Replace missing values in df with 0
df.drop_duplicates()
Remove duplicate rows in df
df.rename(columns={"c1": "C1"})
rename column “c1” to “C1”
df["c1"].astype(float)
convert column “c1” to floats
df.groupby("Road")["Speed"].mean()
show average value of “Speed” (column) for each road in “Road”
df.describe()
Statistical analysis of df (mean, max, min, std)