我有一列包含工作日,另一列包含月份和年份。如何在python中获取实际日期?
import pandas as pd
df = pd.DataFrame({"year": [2018], "month": [12], "day": [1]})
df["date"] = pd.to_datetime(df[["year", "month", "day"]]).dt.date
print(df)
# year month day date
# 0 2018 12 1 2018-12-01
您可以使用日期时间库:
import datetime
x = datetime.datetime(year, month, day)
print(x)
文件:https://docs.python.org/3/library/datetime.html
from datetime import date
print(date.today())
这应该有效!