teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

コメントアウトしてたミス

2018/09/26 12:04

投稿

takey
takey

スコア312

answer CHANGED
@@ -16,12 +16,11 @@
16
16
  with cd.open(filepath, "r", "shift-jis", "ignore") as csv_file: # 追加
17
17
  filename = pd.read_table(csv_file)
18
18
 
19
- """
20
19
  listT = []
21
20
  listV = []
22
21
  listT = filename['time']
23
22
  listV = filename['value']
24
- """
23
+
25
24
  type = input('please input type.\n1:curve\r2:average')
26
25
  if type == '1':
27
26
  res = np.polyfit(listT,listV,10)

1

プログラムミス

2018/09/26 12:04

投稿

takey
takey

スコア312

answer CHANGED
@@ -1,7 +1,47 @@
1
1
  SHIFT-JISを指定しているようですが、UTF-8でデコードしています。
2
2
 
3
3
  ```python
4
+ from scipy.optimize import curve_fit
5
+ import seaborn as sns
6
+
7
+ import sys
8
+ import codecs as cd # 追加
9
+ import pandas as pd
10
+ import numpy as np
11
+ import matplotlib.pyplot as plt
12
+
13
+ sys.setrecursionlimit(100000)
14
+ filepath = input('please input file path.')
4
- filename = pd.read_csv(filepath, encoding="shift-jis", "ignore")
15
+ #filename = pd.read_csv(filepath, encoding="SHIFT-JIS", "ignore") # コメントアウト
16
+ with cd.open(filepath, "r", "shift-jis", "ignore") as csv_file: # 追加
17
+ filename = pd.read_table(csv_file)
18
+
19
+ """
20
+ listT = []
21
+ listV = []
22
+ listT = filename['time']
23
+ listV = filename['value']
24
+ """
25
+ type = input('please input type.\n1:curve\r2:average')
26
+ if type == '1':
27
+ res = np.polyfit(listT,listV,10)
28
+ y2 = np.poly1d(res)(listT)
29
+ plt.figure(figsize=(20,10))
30
+ plt.plot(listT,listV,label='ori')
31
+ plt.plot(listT,y2,label='curve_fit')
32
+ else:
33
+ num = 10000
34
+ b = np.ones(num)/num
35
+ y2 = np.convolve(listV, b, mode='same')
36
+ plt.figure(figsize=(20,10))
37
+ plt.plot(listT,listV, label='ori')
38
+ plt.plot(listT,y2, label='ave')
39
+
40
+ plt.legend()
41
+ plt.show()
42
+
43
+ input()
44
+
5
45
  ```
6
46
 
7
47
  でどうでしょうか。"ignore"オプションはデコードエラーの部分を無視して読み込みます。