前提・実現したいこと
python3で
"2018/ 9/29 19:27:28","01","123456789B","00","0B","1235","362F","10E2","223E"," 000","80","00"," 000"," 000"," 000"," 000"," 000"
"2018/ 9/29 19:27:28","02","123456789A","00","0A","1234","362E","10E1","223D"," 000","80","00"," 000"," 000"," 000"," 000"," 000"
"2018/ 9/29 19:27:28","03","123456789B","00","0B","1235","362F","10E2","223E"," 000","80","00"," 000"," 000"," 000"," 000"," 000"
と書かれているようなtxtファイルを読み込みんで "0B"や"0A"の後ろ4列だけを抽出したいのですが
下記のようなエラーメッセージが出ます。
過去に数字だけが書かれているtxtファイルは読み込んだことがあるのですが、”や/が使われているデータは読んだことがありません。
どなたかご教授いただければ幸いです。
発生している問題・エラーメッセージ
UnicodeDecodeError Traceback (most recent call last) <ipython-input-1-146f274a0966> in <module> 1 import numpy as np 2 ----> 3 xp, xm, yp, ym = np.genfromtxt("pppet.txt",skip_header=1,usecols=[7,8,9,10], delimiter=",",unpack=True) 4 print(xp,xm,yp,ym) ~/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows, encoding) 1792 try: 1793 for i in range(skip_header): -> 1794 next(fhd) 1795 1796 # Keep on until we find the first valid values ~/opt/anaconda3/lib/python3.7/codecs.py in decode(self, input, final) 320 # decode input (taking the buffer into account) 321 data = self.buffer + input --> 322 (result, consumed) = self._buffer_decode(data, self.errors, final) 323 # keep undecoded input until the next call 324 self.buffer = data[consumed:] UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 0: invalid start byte
該当のソースコード
1行目にはデータが何か日本語で記述されているので飛ばして読み込んでいます。
python3
1import numpy as np 2 3xp, xm, yp, ym = np.genfromtxt("pppet.txt",skip_header=1,usecols=[7,8,9,10], delimiter=",",unpack=True) 4print(xp,xm,yp,ym)
試したこと
上述の通りです。
補足情報(FW/ツールのバージョンなど)
jupyter notebook で書いてます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/16 08:14