Advertisement

datamatrix.convert

Convert between DataMatrix objects and types of data structures (notably pandas.DataFrame).

function from_pandas(df)

Converts a pandas DataFrame to a DataMatrix.

Example:

import pandas as pd
from datamatrix import convert

df = pd.DataFrame( {'col' : [1,2,3] } )
dm = convert.from_pandas(df)
print(dm)

Output:

+---+-----+
| # | col |
+---+-----+
| 0 |  1  |
| 1 |  2  |
| 2 |  3  |
+---+-----+

Arguments:

  • df -- No description
    • Type: DataFrame

Returns:

No description

  • Type: DataMatrix

function to_pandas(dm)

Converts a DataMatrix to a pandas DataFrame.

Example:

from datamatrix import DataMatrix, convert

dm = DataMatrix(length=3)
dm.col = 1, 2, 3
df = convert.to_pandas(dm)
print(df)

Output:

   col
0    1
1    2
2    3

Arguments:

  • dm -- No description
    • Type: DataMatrix

Returns:

No description

  • Type: DataFrame