简体   繁体   中英

Hierarchical data pandas

I want to analyze data from a simulation. The data is organized by the structure of the model:

Ie the Model has Nodes. Each node has a position and a speed. Each position has an x, y and z component. Each component has a value for every time step in the simulation.

To organize the data I began writing an object that stores all the values so that I can get to a time series of a component by calling something like:

values = simulation.nodes(13).position.x(:)

Then I heard about pandas and how it provides some usefull sorting and analysis tools. Could I use pandas to do what I want to do? Or should I write my own object using ndarrays?

Thanks for your answers.

Ben

Yes, Pandas can do what you want. I'd recommend using a Panel , a three-dimensional data structure. If we consider the panel to be divided into rows, columns, and layers, then each layer could correspond to a node, each column could correspond to a measurement (so you'd have six columns, three for the components of position and three more for the components of velocity), and each row to a time. The Panel has methods that make it easy to sort the data by whatever criteria you like, to extract the parts corresponding to certain times or time ranges or certain nodes, to resample, interpolate, and otherwise process the data, and even to separate the position data from the velocity data. You would probably find it helpful to use aMultiIndex for the columns, which allows you to have multi-level column labels that combine into groups - that way you could have a group for position and another group for velocity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM