Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a file with 13 columns, I want the first column to be one variable which I have and I want all the other 12 to be put together so I can get their mean and other measurements as well as turn them into a histogram. I have it so I can get the first like I said and one of the columns but how do I modify this code to include all 12 columns in y?

What I have tried:

import numpy as np

data = np.loadtxt("EP305Formal2.txt",float,skiprows=1)

xcol, ycol = 0, 12
x, y = data[:,xcol], data[:,ycol]


print(y)
Posted
Updated 10-May-20 5:14am

1 solution

You only need to declare the column where the split occurs:
Python
xx = 1 # break at column 1
x, y = data[:xx], data[xx:] # x gets first column, y gets the rest
print ("X: ", x)
print ("Y: ", y)

And you do not want those extra commas in the slice definitions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900