typecasting typecasting or converting data into appropriate data typesis an important part of cleanup and wrangling in general often data gets converted into wrong data types while being extracted or converted from one form to the other also different platforms and systems handle each data type differently and thus getting the right data type is important while starting the wrangling discussionwe checked upon the data types of all the columns of our dataset if you rememberthe date column was marked as an object though it may not be an issue if we are not going to work with datesbut in cases we need date and related attributeshaving them as objects/strings can pose problems moreoverit is difficult to handle date operations if they are available as strings to fix our dataframewe use to_datetime(function from pandas this is very flexible utility that allows us to set different attributes like date time formatstimezoneand so on since in our casethe values are just dateswe use the function as follows with defaults df['date'pd to_datetime(df dateprint(df dtypessimilarlywe can convert numeric columns marked as strings using to_numeric(along with direct python style typecasting as well upon checking the data types nowwe clearly see the date column in the correct data type of datetime date datetime [nsprice float product_id int quantity_purchased int serial_no int user_id int user_type object dtypeobject transformations another common task with data wrangling is to transform existing columns or derive new attributes based on requirements of the use case or data itself to derive or transform columnpandas provide three different utilities--apply()applymap()and map(the apply(function is used to perform actions on the whole objectdepending upon the axis (default is on all rowsthe applymap(and map(functions work element-wise with map(coming from the pandas series hierarchy as an example to understand these three utilitieslet' derive some new attributes firstlet' expand the user_type attribute using the map(function we write small function to map each of the distinct user_type codes into their corresponding user classes as follows def expand_user_type(u_type)if u_type in [' ',' ']return 'newelif u_type =' 'return 'existingelif u_type =' 'return 'loyal_existingelsereturn 'errordf['user_class'df['user_type'map(expand_user_type