0

I'm trying to make a histogram, and i've been doing some searches and trying to find the right code, but everything I try doesn't end up working. This is my code right now,

import matplotlib.pyplot as plt
import numpy as np

with open('gaubg.csv') as f:
       v = np.loadtxt(f, delimiter= ',', dtype="float", skiprows=1, usecols='None')

plt.hist(v, bins=100)
plt.xlabel("G-r0")
plt.ylabel('# of stars')
plt.title("Bottom half g-r0")

plt.show()

gaubg.csv is a csv file that includes about 600,000 (float, not int) data points that have to do with the color of stars. Every time I run this through python, this is the error message that shows up

Traceback (most recent call last): File "gaub.py", line 5, in v = np.loadtxt(f, delimiter= ',', dtype="float", skiprows=1, usecols='None') File "/sdss/ups/prd/numpy/v1_6_1/Linux/lib/python2.7/sitepackages/numpy/lib/npyio.py", line 794, in loadtxt vals = [vals[i] for i in usecols] TypeError: list indices must be integers, not str

I have no idea what that means. I've been trying to fix the code but I'm not sure how. If you could point out the obvious error(s) I'd be grateful!

1 Answer 1

4
usecols= 'None' 

should be

usecols= None

Or you can skip adding the usecols argument altogether. When you specified a string numpy tried to iterate through each character with the assumption that it's an integer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.