私はある列に日付のリストと別の列に値のリストを持っています。Python Excelの2つの列のリスト
2/8/13 474
2/7/13 463.25
2/6/13 456.47
2/5/13 444.05
2/4/13 453.91
2/1/13 459.11
1/31/13 456.98
1/30/13 457
1/29/13 458.5
1/28/13 437.83
1/25/13 451.69
1/24/13 460
1/23/13 508.81
1/22/13 504.56
1/18/13 498.52
1/17/13 510.31
最初の列の日付をコンパイルし、その月の平均値を出力する方法を見つける必要があります。
出力は 月:year average_value_for_monthのようになります。
例えば、最初の二つの出力が^
02:2013 458.46
01:2013 500.08
のようになります。これは、2013年2月、1月のヶ月間、平均値は、今の私のコード458.46,500.08
あったと述べています、
def averageData(list_of_tuples):
#print(list_of_tuples) #prints out the list obtained from getDataList
sep_list = []
for i in range(0,len(list_of_tuples)):
split_list = list_of_tuples[i].split()
sep_list.append(split_list)
#print(sep_list[i]) #prints out list with index [i][0] being the date and index [i][1] being the column value
new_list = []
for i in range(0,len(sep_list)):
sep_list[i][0] = sep_list[i][0].split('-') #splits dates in year, month, day
#print(sep_list[i][0])
print(sep_list[i][0])
for i in range(0,len(sep_list)):
if sep_list[i][0][0] == sep_list[i+1][0][0] and sep_list[i][0][1] == sep_list[i+1][0][1]:
new_date = sep_list[i][0][1]+':'+sep_list[i][0][0]
new_list.append(new_date)
#print(new_list[i])
元のリストは
['2013-02-08 474.00']
のようにフォーマットされています
ループのための私の最初は
['2013-02-08', '474.00']
なっリストは、ループための第二は、私がここからどこへ行くにこだわっている
[['2013', '02', '08'], '474.00']
にリストに変わります。助けてください。
ピボットテーブルを使ってみてください! http://stackoverflow.com/questions/15570099/pandas-pivot-tables-row-subtotals –