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)

11th Dec 2022, 11:18 AM
ARBEIT MANN
ARBEIT MANN - avatar
2 Respuestas
+ 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
11th Dec 2022, 3:22 PM
Lothar
Lothar - avatar
+ 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.
11th Dec 2022, 11:56 AM
Calviղ
Calviղ - avatar