Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert input time value to datetime

# converting input time value to datetime.
def conv_time(time_val):
    if pd.isnull(time_val):
        return np.nan
    else:
            # replace 24:00 o'clock with 00:00 o'clock:
        if time_val == 2400: time_val = 0
            # creating a 4 digit value out of input value:
        time_val = "{0:04d}".format(int(time_val))
            # creating a time datatype out of input value: 
        time_formatted = datetime.time(int(time_val[0:2]), int(time_val[2:4]))
    return time_formatted
    
    
#Example on how to use our function:

df['ARRIVAL_TIME'] = df['ARRIVAL_TIME'].apply(conv_time)
df['DEPARTURE_TIME'] = df['DEPARTURE_TIME'].apply(conv_time)
Comment

PREVIOUS NEXT
Code Example
Python :: string to 2d array python 
Python :: python for infinite range 
Python :: Distribute Candy Algorithm Python 
Python :: save media file from url python 
Python :: list data structure in python 
Python :: Basic Routing In Python 
Python :: check if a PID exists on a UNIX based system 
Python :: using return values python script in batch script 
Python :: Display summary of all the numerical variables in the DataFrame 
Python :: how to remove hidden white spaces n columns 
Python :: PySimpleGUI and tkinter with camera on Android 
Python :: how to combine sets using union() function 
Python :: Move Mouse Every Minute Using Python 3 & PyAutoGUI 
Python :: save PIL image to s3 
Python :: os scan dir python 2 
Python :: is c++ easier than python 
Python :: python error bars 
Python :: python enum key string get 
Python :: database setup in django aws 
Python :: enumerate for string 
Python :: find the index of nanmax 
Python :: python two list into dictinaray 
Python :: pyqt5 different resolutions 
Python :: problem 1 dot product python 
Python :: how to preserve white space when joining an array python 
Python :: pandas df to R df 
Python :: gym for creating simple grid world 
Python :: create loading in pyqt 
Python :: student notebook (finish), INB (finish), Food and Fitness log (log necessary), debate speech (finish) 
Python :: Access the Response Methods and Attributes in python 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =