Skip to content

Cheatsheet -- Python & Pandas

CategoryOperatorDescriptionExample
Arithmetic+ - * /Basic Math10 / 2 = 5.0
//Floor Division (removes decimal)10 // 3 = 3
%Modulus (remainder)10 % 3 = 1
**Exponentiation (Power)2 ** 3 = 8
Assignment=Assign valuex = 5
+= -=Increment/Decrementx += 1
:=Walrus (assign inside expression)if (n := len(a)) > 10:
Comparison== !=Equal / Not Equalx == 5
> <Greater / Less thanx > 10
LogicalandBoth must be TrueTrue and False -> False
orOne must be TrueTrue or False -> True
notInverts Booleannot True -> False
IdentityisSame object in memory?x is None
MembershipinExists in sequence?'a' in 'apple'
TypeSyntaxMutable?Access
List[1, 2, "a"]Yesx[0]
Tuple(1, 2, "a")Nox[0]
Dict{'k': 'v'}Yesx['k']
Set{1, 2, 3}YesN/A (Unordered)
df.head(n) # First n rows
df.shape # (rows, columns)
df.info() # Index, Datatype, Memory info
df.describe() # Statistical summary
df.columns # List of column names
df['col'] # Returns Series
df[['c1', 'c2']] # Returns DataFrame
df.iloc[0] # Selection by position (Integer)
df.loc['index_val'] # Selection by Label
df[df['col'] > 5] # Boolean conditional selection
df.isnull().sum() # Count nulls per column
df.dropna() # Drop rows with nulls
df.fillna(value) # Fill nulls
df.astype(dtype) # Change data type
df.sort_values(by='col') # Sort
df.groupby('col').mean() # Group and aggregate
MethodUse Case
pd.concat([df1, df2])Stacking dataframes vertically or horizontally.
df1.merge(df2)Database-style join on a common column.
df1.join(df2)Joining based on the Index.

Explicit is better than implicit. Simple is better than complex. Readability counts.