Python Practice (Kaggle)
10 flashcards · Programming Languages · by charlie42
Include non-numeric columns in df.describe()
df.describe(include='all')
Print types of all columns in a df
df.dtypes
Get first character from a column
df[col].str[0]
Convert column to a type
df[col] = df[col].astype('str')
Print a sorted array
sorted(a)
Check number of characeters in a column value
df[col].str.len()
Check if some character is in column value
df[col].str.contains("a")
Split by character and take first value
df['first_part'] = df['col'].str.split(' ').str[0]
Rename columns after groupby and aggregation
grouped = df.grouby(col).count().reset_index() grouped.names = ["col", "col_count"] Need reset_index() because otherwise col will become the index
Replace values across df
df = df.replace(['nan', ''], np.nan)