我已經寫了一段腳本,目前我確定可以進行濃縮。我試圖實現的是這種自動版本:追加到迭代字典中的列表
file1 = tkFileDialog.askopenfilename(title='Select the first data file')
file2 = tkFileDialog.askopenfilename(title='Select the first data file')
TurnDatabase = tkFileDialog.askopenfilename(title='Select the turn database file')
headers = pd.read_csv(file1, nrows=1).columns
data1 = pd.read_csv(file1)
data2 = pd.read_csv(file2)
這是如何收集數據。 還有更多的代碼行着重於挑選數據的位。我不會發布這一切。
這就是我想要凝結:
EntrySummary = []
for key in Entries1.viewkeys():
MeanFRH = Entries1[key].hRideF.mean()
MeanFRHC = Entries1[key].hRideFCalc.mean()
MeanRRH = Entries1[key].hRideR.mean()
# There's 30 more lines of these...
# Then the list is updated with this:
EntrySummary.append({'Turn Number': key, 'Avg FRH': MeanFRH, 'Avg FRHC': MeanFRHC, 'Avg RRH': MeanRRH,... # and so on})
EntrySummary = pd.DataFrame(EntrySummary)
EntrySummary.index = EntrySummary['Turn Number']
del EntrySummary['Turn Number']
這是舊代碼。我一直試圖做的是這樣的:
EntrySummary = []
for i in headers():
EntrySummary.append({'Turn Number': key, str('Avg '[i]): str('Mean'[i])})
print EntrySummary
# The print is only there for me to see if it's worked.
但是我在一分鐘收到此錯誤:
for i in headers():
TypeError: 'Index' object is not callable
任何想法,我犯了一個錯誤?我可能做了一些...
預先感謝您
奧利
現在在哪裏定義'headers'? –
標題與沒有更改的第一段數據相同。道歉我沒有說清楚 – OParker
'print header'給你什麼? –