andyolivers
andyolivers

Reputation: 43

Get date from weekday, month and year

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?

Upvotes: 1

Views: 222

Answers (3)

Jamie.Sgro
Jamie.Sgro

Reputation: 882

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

Upvotes: 2

Anton Chernyshov
Anton Chernyshov

Reputation: 109

from datetime import date

print(date.today())

This should work!

Upvotes: 0

jliu
jliu

Reputation: 36

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

Upvotes: 0

Related Questions