0
The Compiler says the input for column name is not a valid string
import numpy as np filename = input() column_name = input() data = np.loadtxt(filename, delimiter=",") column = np.array(data[column_name]) print(column)
2 Answers
+ 5
SINKREAN VAEGAN GATES KLINĂMANN ,
as already mentioned by CalviŐ˛ , we need an integer number to access the numpy rows or columns of an array.
(please see your code sample (in the attached file) that is modified slightly. i also renamed the input variable *column_name* to *ind*)
> the code: column = np.array(data[ind]) does access a *row* of the current array.
> if we need to get a column of the array, we can do it this like: column = data[:, ind]
https://code.sololearn.com/clPpa83V6Y5Z/?ref=app
+ 1
In order to access a specific column in a NumPy array, you need to use the index of the column rather than its name.