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


for object in objects:
    objectname =

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

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


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

    while scene.frame_current <= frame_end:

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

        scene.frame_set(scene.frame_current + frame_step)