Home > other >  How to use python to three columns of data into matrix form
How to use python to three columns of data into matrix form

Time:09-20

I have three columns of data, for example: three columns are the x, y, z, want to use python converts it to the matrix form, request matrix transverse is x, longitudinal is y, matrix in the internal value of z, like pandas, transverse index for x, longitudinal index to y, internal for z,

400 0.35 32.28395
 
400 0.45 33.29445
400 0.55 34.1344
400 0.65 33.28456
400 0.75 31.64976
400 0.85 20.67029
420 0.35 41.23088
420 0.45 42.53433
420 0.55 41.87417
420 0.65 41.91008
420 0.75 41.71394
420 0.85 41.1083
420 0.95 40.14541
420 1.05 39.34686
420 1.15 38.60253
420 1.25 37.80679
420 1.35 36.79494
420 1.45 4.45929
440 0.35 29.76642
440 0.45 29.52622
440 0.55 30.05226
440 0.7 29.83975
440 0.9 29.91192
440 1.1 30.62344
440 1.3 30.80821
440 1.5 30.53559

CodePudding user response:

A method are stupid, don't know whether I understand the meaning

The import pandas as pd
The import numpy as np

X=[]; Y=[]; Z=[]
With the open (" 1. TXT ", "r") as f:
Data=(https://bbs.csdn.net/topics/f.readlines)
For I in data:
I=i. trip (' \ n '). The split (' ')
X.a ppend (I [0])
Y.a ppend (I [1])
Z.a ppend (I [2])
DF=pd DataFrame (index=y, the columns=x)
For I in range (len (x)) :
For j in range (len (y)) :
If I==j:
DF. Iat [I, j]=float (z [I])
DF=DF fillna (0)
MAT=np. MAT (DF)
Print (MAT)
  • Related