Python Script to Convert Date Column to DateTime Format
Assuming your date column is in the format of 'YYYY-MM-DD', the following Python script can be used to convert it into a datetime format:
import pandas as pd
# read in your dataset
df = pd.read_csv('your_dataset.csv')
# convert the date column to datetime
df['date'] = pd.to_datetime(df['date'])
# print the updated dataset
print(df)
If your date column is in a different format, you may need to adjust the pd.to_datetime function accordingly. For example, if your date column is in the format of 'MM/DD/YYYY', you can use the following:
df['date'] = pd.to_datetime(df['date'], format='%m/%d/%Y')
原文地址: https://www.cveoy.top/t/topic/nTKc 著作权归作者所有。请勿转载和采集!