Answers for "pandas categorical"

2

display all categorical column in pandas dataframe

# get all categorical columns in the dataframe
catCols = [col for col in df.columns if df[col].dtype=="O"]
Posted by: Guest on May-30-2021
1

using df.astype to select categorical data and numerical data

df = pd.DataFrame({'vertebrates': ['Bird', 'Bird', 'Mammal', 'Fish', 'Amphibian', 'Reptile', 'Mammal']})

df.vertebrates.astype("category").cat.codes
Posted by: Guest on June-01-2020
0

how to make a column a factor in pandas

df['col_name'] = df['col_name'].astype('category')
Posted by: Guest on November-20-2020
0

treat NaN as a category

g_without_nan = g.cat.add_categories("D").fillna("D")
Posted by: Guest on July-23-2020

Code answers related to "pandas categorical"

Python Answers by Framework

Browse Popular Code Answers by Language