Rex Yeigh Rex Yeigh - 10 months ago 77
Python Question

Generating Plots from .csv file

I'm trying to make several plots of Exoplanet data from NASA's Exoplanet Archive. The problem is nothing I do will return the columns of the csv file with the headers on the first line of the csv file.

The Error I get is

NameError: name 'pl_orbper' is not defined

The DATA I need to use.

The code I have currently has not worked though I'm sure I'm close.

import matplotlib.pyplot as plt
import numpy as np

data = np.genfromtxt("planets.csv",delimiter=',',names=True, unpack=True)

plt.title('Mass vs Period')

If anyone has a better solution with csv.reader or any other ways to read csv files I'd be open to it.

Answer Source

Change the following line




With the following data:

1, 326.03, 0.320
2, 327.03, 0.420
3, 328.03, 0.520
4, 329.03, 0.620
5, 330.03, 0.720
6, 331.03, 0.820

this is the result

Mass vs Period Plot