尝试:
import pandas as pdimport numpy as npraw = []with open('test.txt','r') as f: for line in f: raw.append(line.split())data = pd.Dataframe(raw,columns = ['row','column','value'])data_ind = data.set_index(['row','column']).unstack('column')np.array(data_ind.values,dtype=float))
输出:
array([[ 5., 4., 3.], [ nan, 2., 1.], [ nan, nan, 0.]])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)