将数据 table 转置为时间序列 table
Transpose a data table to a time-series table
我想知道如何将我的数据(1 行 = 参数)转置为时间序列(1 行 = 1 DateTime)
我从 pandas 尝试了 pivot_table 但是...输出中没有列
我希望按日期时间(索引)对值进行分组,然后为每个标记名分组 1 列,以便将值设为 Table 值
#df = my sample of data
df = pd.DataFrame(data= csv, columns = ['DateTime','TagName','Value'])
df.pivot_table(index='DateTime',columns='TagName',values='Value',aggfunc=np.mean)
原始数据:
1
我的 pivot_table 输出:
2
感谢您的帮助。
我的数据样本:
{'DateTime': {0: '2021-10-23 10:14:29.7270000',
1: '2021-10-23 10:14:29.7270000',
2: '2021-10-23 10:14:29.7270000',
3: '2021-10-23 10:14:29.7270000',
4: '2021-10-23 10:14:29.7270000',
5: '2021-10-23 10:14:29.7270000',
6: '2021-10-23 10:14:29.7270000',
7: '2021-10-23 10:14:29.7270000',
8: '2021-10-23 10:14:29.7270000',
9: '2021-10-23 10:14:29.7270000'},
'TagName': {0: 'DepollutionEntree.ChemineeOuvert',
1: 'DepollutionEntree.ConsigneDepol',
2: 'DepollutionEntree.TempForming',
3: 'DepollutionSortie.ChemineeOuvert',
4: 'DepollutionSortie.ConsigneDepol',
5: 'DepollutionSortie.TempForming',
6: 'Etuve.DebitGaz',
7: 'FibrageB1_DebitEauDilution.PV',
8: 'FibrageB2_DebitEauDilution.PV',
9: 'FibrageB3_DebitEauDilution.PV'},
'Value': {0: '0',
1: '45',
2: '59',
3: '0',
4: '66',
5: '62',
6: '6492604',
7: '920.399963378906',
8: '920.039978027344',
9: '912'}}
试试 pivot
:
output = df.pivot("DateTime", "TagName", "Value")
>>> output
TagName DepollutionEntree.ChemineeOuvert ... FibrageB3_DebitEauDilution.PV
DateTime ...
2021-10-23 10:14:29.7270000 0 ... 912
[1 rows x 10 columns]
我想知道如何将我的数据(1 行 = 参数)转置为时间序列(1 行 = 1 DateTime) 我从 pandas 尝试了 pivot_table 但是...输出中没有列
我希望按日期时间(索引)对值进行分组,然后为每个标记名分组 1 列,以便将值设为 Table 值
#df = my sample of data
df = pd.DataFrame(data= csv, columns = ['DateTime','TagName','Value'])
df.pivot_table(index='DateTime',columns='TagName',values='Value',aggfunc=np.mean)
原始数据:
1
我的 pivot_table 输出:
2
感谢您的帮助。
我的数据样本:
{'DateTime': {0: '2021-10-23 10:14:29.7270000',
1: '2021-10-23 10:14:29.7270000',
2: '2021-10-23 10:14:29.7270000',
3: '2021-10-23 10:14:29.7270000',
4: '2021-10-23 10:14:29.7270000',
5: '2021-10-23 10:14:29.7270000',
6: '2021-10-23 10:14:29.7270000',
7: '2021-10-23 10:14:29.7270000',
8: '2021-10-23 10:14:29.7270000',
9: '2021-10-23 10:14:29.7270000'},
'TagName': {0: 'DepollutionEntree.ChemineeOuvert',
1: 'DepollutionEntree.ConsigneDepol',
2: 'DepollutionEntree.TempForming',
3: 'DepollutionSortie.ChemineeOuvert',
4: 'DepollutionSortie.ConsigneDepol',
5: 'DepollutionSortie.TempForming',
6: 'Etuve.DebitGaz',
7: 'FibrageB1_DebitEauDilution.PV',
8: 'FibrageB2_DebitEauDilution.PV',
9: 'FibrageB3_DebitEauDilution.PV'},
'Value': {0: '0',
1: '45',
2: '59',
3: '0',
4: '66',
5: '62',
6: '6492604',
7: '920.399963378906',
8: '920.039978027344',
9: '912'}}
试试 pivot
:
output = df.pivot("DateTime", "TagName", "Value")
>>> output
TagName DepollutionEntree.ChemineeOuvert ... FibrageB3_DebitEauDilution.PV
DateTime ...
2021-10-23 10:14:29.7270000 0 ... 912
[1 rows x 10 columns]