How to add color information from csv file to objects

I have a csv file with xy coordinates and an additional column that I want use as color information and set as a color ramp. Below is an example of the data I have:

Edit: if the color ramp was to go from red (highest number) to blue (lowest number) then I want the spheres with counts equal to 20 to be red and the sphere with count equal to 1 to be blue.

This is really close to what I want to do: How do I import XYZ AND a fourth parameter that adds color to my objects?, but I'm not familiar enough with python to get all the way to the end.

This is what I have so far, any help would be appreciated!

with open("example.csv") as f:
if i==0: continue
x, y = row[0:2]

bpy.ops.mesh.primitive_uv_sphere_add( location = ( float(x), float(y), 0 ) )


• I'm a little confused. Do you want a colorramp node with colors set at various positions or do you want to set vertex colors on vertices at specific locations or something else altogether? Jan 28 at 18:24
• My goal is for the numbers in the color column to be mapped to a color ramp gradient. For example, if the color ramp was to go from red (highest number) to blue (lowest number) then I want the spheres with counts equal to 20 to be red and the sphere with count equal to 1 to be blue. Jan 28 at 19:07

There are several ways you could do it. Here's one:

First create a material all the spheres will use. The nodes should look like:

• The attribute node reads a custom property on the object named color, which should be a number between 0 and 1.
• The color ramp is your desired ramp of course.
• Make note of the name because you'll need it in the script. I called it Ramp Material.

Then a slight modification of your script will work

import bpy, csv
with open("example.csv") as f: