There’s an existing history import button which seems to work well, but there’s no easy way to import loved songs.
Here’s how far I got with doing it myself:
I’ve been able to extract my favorites from LastFM using this handy website: lastfm-tools
I found ListenBrainz’s API supports loved tracks:
However, it seems to require MIDBs, which, looking at the exported data from LastFM, not all of my loved tracks have. The document doesn’t mention if this parameter is optional. Is it optional? If so I guess it might be straightforward to write a script that uses the exported data from the aforementioned website, I could do it myself and post it here.