I have this image (the background is transparent):
I was wondering if there is a way to only render the shadow of the ball, while rendering the rest of the ball transparent?
You can't do this directly in the 3D scene as far as I know. You are probably looking for a "Shadow Catcher" type of material, but this is currently not supported in Blender Cycles yet. There are plans to add it in the future but nothing that works currently.
The only way I know to achieve this currently, is in post production through compositing, using the image you show as a mask to mix it over another image in the Blender Compositor Use it as an inverted mask where dark areas are more opaque as opposed to white areas being more transparent as shown bellow.