panda print type of columns code example
Example 1: python: check type and ifno of a data frame
df.shape
df.info()
df.dtypes
des = df.describe() # Summary
des_num = df.describe(include=[np.number]) # Include only numerical columns
des_obj = df.describe(include=[np.object]) # Include only string columns
des_obj.transpose()
# Show list of variable / columns in DF
df.columns
# Count number of variables / columns in DF
len(df.columns)
# Count variable
df["myvar"].value_counts()
Example 2: pandas check if column is object type
for y in agg.columns:
if(agg[y].dtype == np.float64 or agg[y].dtype == np.int64):
treat_numeric(agg[y])
else:
treat_str(agg[y])