###前提・実現したいこと
Python3で
12.5,13.4,12.9,・・・, 12.5
のようにn個の小数点がならんでいるときにそれを20個の代表データにしたい。
具体的には
n/20づつの平均値を計算して
a,b,d,d,・・・,t (20個の小数点が並んだデータにしたい)
###発生している問題・エラーメッセージ
1行ならばできるようになったのですが複数行で行おうとするとエラーがでます。
エラーメッセージ
ValueError Traceback (most recent call last)
<ipython-input-7-6ed550d9bc09> in <module>()
6 columns = row.rstrip().split(',')
7 for column in columns:
----> 8 n=float(column)
9 list.append(n)
10 repeat = len(list)//20
ValueError: could not convert string to float:
###該当のソースコード
list = []
new_list=[]
new_list_2=[]
with open ('test5.csv', encoding ='utf-8') as f:
for row in f:
columns = row.rstrip().split(',')
for column in columns:
n=float(column)
list.append(n)
repeat = len(list)//20
for t in range (20):
for num in list[trepeat:trepeat+repeat]:
new_list.append(num)
new_value=(sum(new_list)/len(new_list))
new_list_2.append(new_value)
new_list=[]
print (new_list_2)
###試したこと
コードも素人丸出しで申し訳ないです
###補足情報(言語/FW/ツール等のバージョンなど)
複数行ある場合はなぜエラーが出るのでしょうか?
回答2件
あなたの回答
tips
プレビュー