Yes, the 'Date' and 'Time' columns can be combined into a single column named 'Date_Time' using Pandas by using the apply()
method with a lambda function to concatenate the two columns with a space separator:
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame({'Date': ['2021-01-01', '2021-01-02', '2021-01-03'],
'Time': ['12:00:00', '13:30:00', '17:45:00']})
# Combine Date and Time columns into a single column 'Date_Time'
df['Date_Time'] = df.apply(lambda row: row['Date'] + ' ' + row['Time'], axis=1)
print(df)
Output:
Date Time Date_Time
0 2021-01-01 12:00:00 2021-01-01 12:00:00
1 2021-01-02 13:30:00 2021-01-02 13:30:00
2 2021-01-03 17:45:00 2021-01-03 17:45:00
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-16 12:21:55 +0000
Seen: 10 times
Last updated: Jun 16 '23
How can a running tally be created for a group using information from two columns?
How can I include the hours component to a DateTime column using PowerQuery?
Identify commonalities among the strings in a specific column of a DataFrame.
What is the procedure for using Pandas fillna() method with the column's mode?