How do I modify this script to affect bones instead of shape keys?
Something like?
Speculating that the data file is akin to
name value
Bone 10.0
Bone.001 22

and using a string to emulate the file, ie data.splitlines() to emulate a text file buffer. Example below, pose bone &quot;Bone&quot; keyframe location 0 at frame 0,
Run script  with the armature object active and not in edit mode.
import bpy
import csv 

context = bpy.context
ob = context.object
frames_per_line = 20

data = '''Bone, 0
Bone.001, 0.4
Bone.002,  1.0
Bone, 10
Bone, 20
Bone.002, -2.9'''

for frame, (name, value) in enumerate(csv.reader(data.splitlines())):

    pb = ob.pose.bones.get(name)
    if pb:
        pb.location.y = float(value)
        pb.keyframe_insert(
                &quot;location&quot;,
                 index=1,
                 frame=frames_per_line * frame
             ) # y location