Averaging data from multiple data files in Python with pandas

前端 未结 3 1974
南笙
南笙 2021-01-14 11:32

I have 30 csv data files from 30 replicate runs of an experiment I ran. I am using pandas\' read_csv() function to read the data into a list of DataFrames. I wo

3条回答
  •  青春惊慌失措
    2021-01-14 12:15

    Have a look at the pandas.concat() function. When you read in your files, you can use concat to join the resulting DataFrames into one, then just use normal pandas averaging techniques to average them.

    To use it, just pass it a list of the DataFrames you want joined together:

    >>> x
              A         B         C
    0 -0.264438 -1.026059 -0.619500
    1  0.927272  0.302904 -0.032399
    2 -0.264273 -0.386314 -0.217601
    3 -0.871858 -0.348382  1.100491
    >>> y
              A         B         C
    0  1.923135  0.135355 -0.285491
    1 -0.208940  0.642432 -0.764902
    2  1.477419 -1.659804 -0.431375
    3 -1.191664  0.152576  0.935773
    >>> pandas.concat([x, y])
              A         B         C
    0 -0.264438 -1.026059 -0.619500
    1  0.927272  0.302904 -0.032399
    2 -0.264273 -0.386314 -0.217601
    3 -0.871858 -0.348382  1.100491
    0  1.923135  0.135355 -0.285491
    1 -0.208940  0.642432 -0.764902
    2  1.477419 -1.659804 -0.431375
    3 -1.191664  0.152576  0.935773
    

提交回复
热议问题