Python pandas - MultiIndexed Series to Dataframe -


(background: I am trying to learn Pandas and matplotlib and get some good graphs from my good ideas. )

I have managed to parse some data into a multi-indexed series (let's call it series ):

  msgs id Datetime_period A 2014-07-04 07:00 1 2014-07-04 08:00 2 2014-07-08 11:00 5b 2014-07-08 11:00 1C 2014-07-04 07:00 2 < / Code> 

For graphs, I would like to organize it into datafir such as A Looks like something:

  Index ABC 2014-07-04 07:00 1 0 2 2014-07-04 08: 00 2 0 2014-07-08 11:00 5 1 0  

How would I do this? I think I can do something like this for me in ['A', 'B', 'C']} for

  df = DataFrame ({i: series.ix [ I])  

But is there another way to 'Pandu'? (Or if not, how do I get the ['A', 'B', 'C'] list from series instead of clearly writing it above?)

Alternatively (matters In this it is easy to use), there is also a basic 'raw' dataframe available that I used to build series in the first place. It contains a timestamp for each message in each nick, such as:

  Timestamp ID 2014-07-04 07:11:00 A 2014-07-04 07:12:32 C 2014- 07-04 07:15:03 C etc.  

can be used to use the multi index level in the column < Replaces the missing values ​​with Code> Filling 0, as shown in your desired output.

 in  [313]: series.unstack (level = 'id'). 0) Out [313]: ID ABC datetime_period 2014-07-04 07:00:00 1 0 2 2014-07-04 08:00:00 2 0 0 2014-07-08 11:00:00 5 1 0 < / Code> 

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -