This is something we have to just remember per work it's used for. Some rules exist like:
• N-genus is the most common genus. It's often used for living beings: en flicka, en läkare, (doctor) and en häst. But there are exceptions: ett barn and ett lejon. (lion)
• Words for plants of different kinds are almost always n-genus: en björk, (birch) en palm, en ros, en buske, (bush) en blomma. (flower) One important exception is ett träd. (tree)
• Words for days, months, seasons and the like are often n-genus: en sekund, (second) en timme, (hour) en dag, (day) en kväll, (evening) and en vecka. (week) Important exceptions are: ett år, (year) ett kvartal, (quarter) and ett sekel. (century)
• Which ending a noun ends with can also be of help, but there are many exceptions to it. Words ending with -are, -inna, -(t)ör, -log, -(n)ing, -het, -else and -tion are often n-genus: kejsare, (emperor) psykolog, (psychologist) släkting, (relative) skönhet, (beauty) and nation.
The best thing you can do learning a language with this many genus exceptions is to learn the genus along with the word.