Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

how to extract columns from rows in pandas

$
0
0

I have data in txt file. The data is stored as a single column. But I need to extract columns from rows. When I read the data using pd.read_table() method, it returns as a single column and many rows. For example, I have .txt file like that:

  • Date: 23:15
  • Temperature: 20 C
  • Humidity: 40
  • CO2 level: 14
  • Date: 23:20
  • Temperature: 28 C
  • Humidity: 45
  • CO2 level: 18
  • Date: 23:25
  • Temperature: 35 C
  • Humidity: 35
  • CO2 level: 20
  • Date: 23:30
  • Temperature: 22 C
  • Humidity: 52
  • CO2 level: 12

and more .....

As you can see, the Date, Temperature, Humidity, CO2 are repeating, so they should be treated as columns, and values they assign should be treated as rows respect to its category. For example:

DateTemperatureHumidityCO2 level
23:1520 C4014
23:2028 C4518
23:2535 C3520
23:3022 C5212

it should assign like that


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>