Manuel Almeida
Manuel Almeida

Reputation: 183

Can I replace a column with values that are in a text file (space delemited) with values that are in a np.array

I am not a programmer, I am new to python, and I have a lot of difficulty with text files.

The columns are in a text file (.txt space delimited). Can I replace the values in the second column (DLT) with the values that I have in a numpy array?:

  JDAY          DLT         ELWS         T2
   4.0          5.0          6.0        7.0
   3.0          4.0          5.0        6.0
   3.0          5.0          7.0        6.0

data=np.array([6.0,3.0,4.0])

I can take the values from that column with this:

getvalues = np.genfromtxt('file.txt', skip_header=2, names=True)
val=getvalues['DLT']

I have been reading a lot of examples but I can´t find a solution.

Upvotes: 0

Views: 87

Answers (1)

Daniel
Daniel

Reputation: 19547

You should just be able to write:

getvalues['DLT'] = data

The caveat here is getvalues['DLT'] must be equal in length to data.

Upvotes: 2

Related Questions