yearmonth stores the year and the month of each row in the yyyymm format. Supposed the year is 2020 and the month is 1, to get 202001 which is in the format of yyyymm we will have to multply year by 100, then add the results to month in order to get yearmonth in the required format.
How would someone come to this conclusion? What do I need to work on to think more like this? I have been stuck on this problem for many days, I did a lot of research and tried different things. I knew the simplest way would be to add year+month but of course, it was missing that padded ‘0’ for the month of Jan - Sept… Should I study what output Im getting and just work from there? or do I just need to be a better mathematician to be better at this?
Disclaimer; I am just a learner of Python and am not a professional. So, please don’t take what I am going to say seriously .
I guess you can get this kind of sense by getting new perspectives from someone’s code or trying to think of different solutions like you did. Moreover, this is just one of solutions. So, I guess that you don’t have to worry a lot.
I am sure that you have obtained many things from your research. It is fantastic!!
I would second that. Multiplying year by 100 is an ambiguous way to solve the problem and it takes more lines. Clean way would be to convert the format of the date to YYYYMM, using dt.strftime("%Y%m).