Prepositions are necessary, of course, but overuse can make writing sound passive and fussy. For example, the U.S. government has a plain language mandate, and when they talk about omitting unnecessary words, they specifically call out prepositions as a potential problem, saying “Watch out for of, to, on, and other prepositions. They often mark phrases you can reduce to one or two words.”
I see both 'in' and 'on' as superfluous in these particular sentences. I'd suggest instead: "I spent 5 hours learning Python everyday." and "I spent a lot of time researching the problem."