I created this function in Python to check the data type of each column of a DF and make sure it becomes the data type it's supposed to be.
def dataType(df):
'''This function makes sure the data type for all 7 columns of the final dataframe are correct'''
#Day as date type
df["Day"] = pd.to_datetime(df["Day"])
df["Day"] = df["Day"].dt.strftime("%m/%d/%Y")
#Channel, Partner as string type
df[["Channel", "Partner"]] = df[["Channel", "Partner"]].astype(str)
#Spend, Clicks, Impressions, Platform Conversions as float type
df['Platform Conversions'] = df['Platform Conversions'].where(df['Platform Conversions'] == "null", 0)
df[["Spend", "Clicks", "Impressions", "Platform Conversions"]] = df[["Spend", "Clicks", "Impressions", "Platform Conversions"]].astype(float)
return df
And I tested each column with a code like this but they all still output saying all columns are object type. What am I doing wrong?
print(df["Day"].dtypes)