简体   繁体   English

如何将时间序列数据添加到一系列时间序列列表中?

[英]How can I add time series data into a range of time series list?

I have several spreadsheets with specific time series data. 我有一些包含特定时间序列数据的电子表格。 I want to summarize those specific times into a summary sheet with ranges of times. 我想将这些特定时间汇总到带有时间范围的摘要表中。

for example: we have our summary date ranges 例如:我们有汇总日期范围

  • [Dec 21, Dec 22, Dec 23] (midnight to midnight). [Dec 21, Dec 22, Dec 23] (午夜至午夜)。

and the data would be something like this: 数据将是这样的:

  1. Dec 21 10:00 = 15
  2. Dec 21 11:00 = 10
  3. Dec 22 13:00 = 5
  4. Dec 22 16:00 = 10
  5. Dec 23 2:00 = 6
  6. Dec 23 12:00 = 6

Thus I would like the summary to end up being: Dec 21 = 25 , Dec 22 = 15 , Dec 23 = 12 . 因此,我希望总结可以总结为: Dec 21 = 25Dec 22 = 15Dec 23 = 12

I'm using python, datetime, and the openpyxl module to access and create time values. 我正在使用python,datetime和openpyxl模块来访问和创建时间值。

I'm having a hard time getting my head around the creation of the time series list. 我很难理解时间序列表的创建。 as well as the actual addition. 以及实际添加的内容

getting the actual datetimes and values from the individual sheets is easy. 从单个工作表中获取实际的日期时间和值很容易。

for sheet in projectList:
    ws = wb[sheet]
    LOCSum = 0
    LOCList = {}
    for cols in range(8,30):
        LOCDate = ws.cell(row=4, column=cols).value #A datetime
        LOCSum = ws.cell(row=70, column=cols).value #A number
        LOCList = LocList + appendToListOfValues(LOCDate, LOCSum)
    fitListOfValuesIntoSummary(LOCList)

Once I've got LOCDate and LOCSum , how can I put them together into a list that can then be added to the summary? 一旦获得LOCDateLOCSum ,如何将它们放到一个列表中,然后可以将其添加到摘要中? the appendToListOfValues() function that doesn't really exist. 实际上并不存在的appendToListOfValues()函数。 Should it be a dictionary? 应该是字典吗? a Tuple? 一个元组?

then, once I've got a time series list, how do I make it fit into the summary list? 然后,一旦有了时间序列列表,如何使它适合摘要列表? the fitListOfValuesIntoSummary() function that also doesn't exist. fitListOfValuesIntoSummary()函数也不存在。

and the final kicker, what should I do if the data is outside the designated ranges? 以及最后一个步骤,如果数据超出指定范围怎么办? Do I just have it added to a "before" and "After" range for the summary list? 我是否只是将其添加到摘要列表的“之前”和“之后”范围?

Please point me in the direction of some literature as well. 也请向我指出一些文学的方向。

(As I've been typing up this question.) (因为我一直在输入这个问题。)

Would just automatically adding the found value to the summary cell in the excel doc work? 会自动将发现的值自动添加到excel doc工作中的摘要单元格吗?

if LOCDate >= summaryDate+1:
    summaryDate = summaryDate+1
if summaryDate <= LOCDate <= summaryDate+1:
    ws[summary]['correctCol'+'correctRow'].value = ws[summary]['correctCol'+'correctRow'].value + LOCSum

This ended up working for me. 最终为我工作。

for sheet in projectList:
    ws = wb[sheet]
    LOCDate = 0
    LOCSum = 0
    weeklyLOCAvailCol = 7
    for cols in range(8,30):
        LOCDate = ws.cell(row=19, column=cols).value #a datetime
        LOCSum = ws.cell(row=70, column=cols).value #a number
        if LOCDate >= wb[summName].cell(row=4, column=weeklyLOCAvailCol+1).value: #check if the current values date is greater than the next slot.
            weeklyLOCAvailCol += 1 #if so, move up one slot.
        wb[summary].cell(row=LOCAvailpos, column=weeklyLOCAvailCol).value = wb[summary].cell(row=LOCAvailpos, column=weeklyLOCAvailCol).value + LOCSum
#then, add the current LOCSum value to whatever is in the current date range cell.

So what ends up happening is that each summary cell holds the current total of each individual sheet's cell. 所以最终发生的是,每个摘要单元格都保存着每个工作表单元格的当前总数。

H70-J70 on each sheet is summed up in H28 so long as H70-J70 is less than the next time range's first datetime. 只要H70-J70小于下一个时间范围的第一个日期时间,每张纸上的H70-J70都会在H28求和。 and once it's found that K70 is greater than I28 's datetime, then the next set is stored in I28 并且一旦发现K70大于I28的日期时间,则下一组存储在I28

This isn't ideal as it requires an excel spreadsheet, but it slots data into a range. 这不是理想的选择,因为它需要一个Excel电子表格,但会将数据放入一个范围内。 If there was a way to do this faster, I think that would help others. 如果有办法更快地做到这一点,我认为这会对其他人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM