Skip to content
Advertisement

How can I make a new Column “Week” into a dataframe in pandas?

My code is as follows:

JavaScript

How can I add “Week” column and values like “2020-01”, “2020-02”?

“2020-01” means the first week of 2020.

Advertisement

Answer

Get the year using dt year attribute and concatenate with week attribute. zfill is to fill leading zeros.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement