aboutsummaryrefslogtreecommitdiff
path: root/docs/user_guide/timestamped_data/pandas_dataframe_conversion.md
blob: 7614e736996228ac0452d42d3460f7a926e6d95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
---
title: Pandas DataFrame conversion
---

Pandas DataFrame conversion
===========================

A [Pandas DataFrame](https://pandas.pydata.org/docs/getting_started/intro_tutorials/01_table_oriented.html#min-tut-01-tableoriented) is a python data structure allowing powerful table processings.

## Export as dataframe

[TimeStampedBuffer](../../argaze.md/#argaze.DataStructures.TimeStampedBuffer) instance can be converted into dataframe provided that data values are stored as dictionaries.

```python
from argaze import DataStructures

# Create a timestamped data buffer
ts_data = DataStructures.TimeStampedBuffer()

# Store various data as dictionary
ts_data[10] = {"A_key": 0, "B_key": 0.123}}
ts_data[20] = {"A_key": 4, "B_key": 0.567}}
ts_data[30] = {"A_key": 8, "B_key": 0.901}}
...

# Convert timestamped data buffer into dataframe
ts_buffer_dataframe = ts_buffer.as_dataframe()
```

ts_buffer_dataframe would look like:

|timestamp|A_key|B_key|
|:--------|:----|:----|
|10       |0    |0.123|
|20       |4    |0.567|
|30       |8    |0.901|
|...      |...  |...  |

## Import from dataframe

Reversely, [TimeStampedBuffer](../../argaze.md/#argaze.DataStructures.TimeStampedBuffer) instance can be created from dataframe, as a result of which each dataframe columns label will become a key of data value dictionary. Notice that the column containing timestamp values have to be called 'timestamp'.