Multi-dimensional/Nested DataFrame in Pandas

拈花ヽ惹草 提交于 2019-12-11 04:41:16

问题


I would like to store some multidimensional/nested data in a pandas dataframe or panel such that I would like to be able to return for example:

  1. All the times for Runner A, Race A
  2. All the times(and names) for Race A for a certain year say 2015
  3. Split 2 Time for Race A 2015 for all runners

Example data would look something like this, note that not all runners will have data for all years or all races. I have a fair amount of data in the Runner Profile which I'd prefer not to store on every line.

In addition I have another level of data for certain races. So for Race A/2015 for example I would like to have another level of data for split times, average paces etc.

Could anyone suggest a good way to do this with Pandas or any other way?

Name     | Gender | Age
Runner A | Male   | 35
    Race A
        Year | Time     
        2015 | 2:35:09  
            Split 1 Distance | Split 1 Time | Split 1 Pace | etc...
        2014 | 2:47:34
        2013 | 2:50:12
    Race B
        Year | Time
        2013 | 1:32:07

Runner B | Male | 29
    Race A
        Year | Time
        2015 | 3:05:56
            Split 1 Distance | Split 1 Time | Split 1 Pace | etc...

Runner C | Female | 32
    Race B
        Year | Time
        1998 | 1:29:43

来源:https://stackoverflow.com/questions/37744084/multi-dimensional-nested-dataframe-in-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!