简体   繁体   English

列数非常多的Pandas数据透视表

[英]Pandas pivot table with very large number of columns

I have a pandas dataframe df with about 1000 rows but 500 columns. 我有大约1000行但500列的pandas dataframe df The columns are named Run1, Run2, ..., Run500 这些列名为Run1,Run2,...,Run500

The existing index is datetime . 现有索引为datetime

Sample data from dataframe is as follows: 来自数据帧的样本数据如下:

df.ix[1:4,1:4]
                       Run1    Run2    Date
2019-04-01 01:00:00  23.0263  23.0263  2019-04-01
2019-04-01 01:00:00  19.2212  19.2212  2019-04-01
2019-04-02 01:00:00  19.3694  19.3694  2019-04-02
2019-04-02 01:00:00  19.3694  19.3694  2019-04-02

I can do the trying the following: 我可以尝试以下操作:

pd.pivot_table(df, index=['Date'], values=['Run1'], aggfunc=[np.mean])['mean']

But I need to the following: 但是我需要以下几点:

import pandas as pd
import numpy as np
pd.pivot_table(df, index=['Date'], values=['Run1', 'Run2', ...., 'Run500'], aggfunc=[np.mean])['mean']

我认为这是groupby +的mean

df.groupby('Date').mean()

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

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