我有一個關于作業日的專欄,另一個是關于月份的專欄,另一個是關于年份的專欄。如何在 python 中獲取實際日期?
uj5u.com熱心網友回復:
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
uj5u.com熱心網友回復:
您可以使用日期時間庫:
import datetime
x = datetime.datetime(year, month, day)
print(x)
檔案:https ://docs.python.org/3/library/datetime.html
uj5u.com熱心網友回復:
from datetime import date
print(date.today())
這應該作業!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/519641.html
