Yes you can swap those words if you want to. They have practically the same meaning, but they sometimes sound better in different contexts.
"Nearly" has a slight implication of proximity ("near to a location"). "Almost" has a slight implication of counting ("mostly all of the totality"). But in nearly all scenarios - in almost all scenarios - they're fluidly interchangeable. You probably won't make any mistake if you treat them as perfect synonyms.