Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
981 B
2
Indexable
Never
This is the code-

def data_pre_processing(data):
    # Convert the 'creation_date' and 'resolution_date' columns to datetime
    data['created_date']=pd.to_datetime(data['created_date'])
    data['ticket_resolution_date']=pd.to_datetime(data['ticket_resolution_date'])
    data['ticket_resolution_time']=data.apply(lambda row:row['ticket_resolution_date']-row['created_date'],axis=1)
    data['ticket_resolution_time'] =data['ticket_resolution_time'].apply(lambda x: x.total_seconds() / 3600)
    data.drop(columns=['ticket_resolution_date','created_date'],axis=1 ,inplace=True)
    
    ## Convert all text columns to lowercase
    text_columns=[col for col in data.columns if data[col].dtype=='O']
    data[text_columns]=data[text_columns].apply(lambda x : x.str.lower())
    
    data['ticket_desc'] = data['ticket_desc'].apply(preprocess_text)
    #print(data)
    return data

I want to reuse this function for context preprocessing-

def data_pre_processing_context(data):