[英]Transpose a data table to a time-series table
I am wondering how I can transpose my data (1 row = parameter) to time-series (1 row = 1 DateTime) I tried pivot_table from pandas but... no column in output我想知道如何将我的数据(1 行 = 参数)转换为时间序列(1 行 = 1 个日期时间)
I expect to have the values grouped by DateTime (Index), then 1 column for each TagName in order to have Value as Table values我希望将值按日期时间(索引)分组,然后每个 TagName 有 1 列,以便将值作为表值
#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)
original data:原始数据:
My output with pivot_table:我的 output 与 pivot_table:
Thanks for your help.谢谢你的帮助。
my sample of data:我的数据样本:
{'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'}}
Try with pivot
:尝试使用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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.