Home > Blockchain >  Get date from weekday, month and year
Get date from weekday, month and year

Time:10-25

I have a column with the weekday, another with the month and another with the year. How do I get the actual date in python?

CodePudding user response:

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

CodePudding user response:

You can use the datetime library:

import datetime

x = datetime.datetime(year, month, day)

print(x)

Documentation: https://docs.python.org/3/library/datetime.html

CodePudding user response:

from datetime import date

print(date.today())

This should work!

  • Related