3 回答

TA貢獻1874條經(jīng)驗 獲得超12個贊
您的分隔符必須是逗號 ',' 而不是分號 ';'
編輯:問題是也有逗號,例如 1,25e+00 需要單獨解析
def genfromtxt(file):
from io import BytesIO
with open(file, 'r') as f:
lines = ' '.join([s.replace(',', '.') for s in f.readlines()])
return np.genfromtxt(BytesIO(lines.encode('utf-8')), delimiter=';', dtype=np.float32)
這是我的解決方案

TA貢獻1806條經(jīng)驗 獲得超5個贊
您可以執(zhí)行以下操作來轉換逗號小數(shù):
def conv(x):
return x.replace(',', '.').encode()
read = np.genfromtxt((conv(x) for x in open("x.csv")), delimiter=';')
>>> read
array([[120.4619 , 1.639486],
[121.4262 , 1.623145],
[122.3904 , 1.607553],
[123.3547 , 1.592153],
[124.3189 , 1.576472],
[125.2832 , 1.56022 ],
[126.2474 , 1.543355],
[127.2117 , 1.526069],
[128.1759 , 1.508706],
[129.1402 , 1.491635],
[130.1044 , 1.475144],
[131.0686 , 1.459387],
[132.0329 , 1.444416]])
添加回答
舉報