0

How can i convert mysql database which looks like:

ID  NAMES   OS     Version   TestField   Date
1   names   os1    1.1.2     Tatata      10.11
2   name2   os2    1.1.3     Tatata2     11.11
3   name3   os3    1.1.4     Tatata3     12.3
4   name4   os4    1.1.2     Tatata4     12.4
... ...     ...    ....      ...         ....

Into:

ID        1
NAMES     names
OS        os1
Version   1.12
TestField Tatata
Date      10.11

ID        2
NAMES     names2
OS        os2
Version   1.1.3
TestField Tatata2
Date      11.11
....

end etc...

I already tried use pandas but unlucky I am not very friendly with this lib

robotiaga
  • 315
  • 2
  • 11

1 Answers1

0

With pandas you can use:

out = df.stack().droplevel(0).rename_axis('variable').rename('value').reset_index()
print(out)

# Output
     variable    value
0          ID        1
1       NAMES    names
2          OS      os1
3     Version    1.1.2
4   TestField   Tatata
5        Date    10.11
6          ID        2
7       NAMES    name2
8          OS      os2
9     Version    1.1.3
10  TestField  Tatata2
11       Date    11.11
12         ID        3
13      NAMES    name3
14         OS      os3
15    Version    1.1.4
16  TestField  Tatata3
17       Date     12.3
18         ID        4
19      NAMES    name4
20         OS      os4
21    Version    1.1.2
22  TestField  Tatata4
23       Date     12.4
Corralien
  • 109,409
  • 8
  • 28
  • 52