importing csv files as location keyframes

I have been using this script to export animation (location) as csv files. Now I would like to reimport the file to an object as location keyframes again. It seems really easy, but I got stuck, so I am hoping that someone in this cool forum could help :slight_smile:

2nd question: If I only would like to export or import every 6th frame for example. How could I do that?

import bpy, csv

scene = bpy.context.scene

objects=bpy.context.selected_objects


for object in objects:
    objectname = object.name

    frame_start = scene.frame_start
    frame_end = scene.frame_end
    frame_step = scene.frame_step


    filepath = "E:/SHM/test/" + object.name + ".csv"

    

    f = open(filepath, "w")
    writer = csv.writer(f)
    scene.frame_set(frame_start)

    while scene.frame_current <= frame_end:

        objectloc = object.location
        writer.writerow([scene.frame_current, objectloc[0], objectloc[1], objectloc[2]])
        print(object.location)


        scene.frame_set(scene.frame_current + frame_step)