-1

Current DF 1 Pandas DF is available in this format but I want to convert in another format which is image 2.

Need to convert in this format

Please provide any idea about how can i convert.

Chio
  • 43
  • 4
  • see dupe - also have a read of [mcve] and [ask] images are not acceptable for examples on stackoverflow. – Umar.H Dec 21 '21 at 13:02

1 Answers1

1

Use pd.melt:

out = df.melt(['DateTime', 'Machine'], var_name='Variable', value_name='Value') \
        .sort_values('DateTime', ascending=False).reset_index(drop=True)
print(out)

# Output:
              DateTime Machine     Variable  Value
0  2021-02-01 09:26:00      GE  Temperature     30
1  2021-02-01 09:26:00      GE        Speed   1200
2  2021-02-01 09:25:00      GE  Temperature     32
3  2021-02-01 09:25:00      GE        Speed   1200
4  2021-02-01 09:24:00      GE  Temperature     35
5  2021-02-01 09:24:00      GE        Speed   1200
6  2021-02-01 09:23:00      GE  Temperature     26
7  2021-02-01 09:23:00      GE        Speed   1200
8  2021-02-01 09:22:00      GE  Temperature     31
9  2021-02-01 09:22:00      GE        Speed   1200
10 2021-02-01 09:21:00      GE  Temperature     32
11 2021-02-01 09:21:00      GE        Speed   1200
12 2021-02-01 09:20:00      GE  Temperature     35
13 2021-02-01 09:20:00      GE        Speed   1200
14 2021-02-01 09:19:00      GE  Temperature     38
15 2021-02-01 09:19:00      GE        Speed   1200
Corralien
  • 109,409
  • 8
  • 28
  • 52