fork download
  1. import re
  2. import pandas as pd
  3.  
  4. energy = ['Wind 1,00 Water 7,36 Renewable Cogeneration 9,71 Other Renewables 9,65 Solid Waste 2,80',
  5. 'Fossil Cogeneration 2,17 ',
  6. 'Natural Gas 56,35 Coal 9,73 Nuclear 0,64']
  7. table_energy = []
  8. pattern = r"(\S.*?)\s+(\d+,\d+)"
  9. for i in energy:
  10. for tup in re.findall(pattern, i):
  11. table_energy.append(tup)
  12.  
  13. res = pd.DataFrame(table_energy, columns=['key', 'value'])
  14.  
  15. print(res)
Success #stdin #stdout 0.42s 57936KB
stdin
Standard input is empty
stdout
                      key  value
0                    Wind   1,00
1                   Water   7,36
2  Renewable Cogeneration   9,71
3        Other Renewables   9,65
4             Solid Waste   2,80
5     Fossil Cogeneration   2,17
6             Natural Gas  56,35
7                    Coal   9,73
8                 Nuclear   0,64