I am totally beginner in python. I wrote the code which gave me the number below. In this number I have a year month and day in the one word string. I want to know how can I remove the days ( I mean two digits from the right):
20220612
20220819
20220926
I wrote the code which is like this:
temporary_data = {
                'year': year[i].text,
                'month':'',
                'imp/exp':'1',
                'commodities': commodities[i].text,
                'countries': countries[i].text,
                'quantities': quantities[i].text,
                'weights': weights[i].text }
            #-----------------------------------------------------
            temporary_data['year']=temporary_data['year'].replace('-', '')          #code for eleminating the - between year and month
            temporary_data['year']=temporary_data['year'][:-2]                      #code for eleminating the days number
            temporary_data['month']=temporary_data['year'][4:]
            tempor ary_data['year']=temporary_data['year'][:4] 
            #------------------------------------------------------
            if '—' in temporary_data['commodities']:
                    temporary_data['commodities'] = temporary_data['commodities'].replace(".", "")
                    temporary_data['commodities'] = temporary_data['commodities'].split(' —')[-2]
                    temporary_data['commodities']=temporary_data['commodities'][0:6]
after the code runs it should become to the below data:
2022,06
2022,08
2022,09
I don't know why it doesn't work!
 
     
     
    