Home > OS >  Converting Data into pandas data frame format
Converting Data into pandas data frame format

Time:01-09

I have following dummy calculation in Python language

from datetime import datetime
import pandas as pd

result = ### based on some calculation

print(result)

With this I am getting answer in below format:

(
    (
        'date', pywintypes.datetime(2020, 6, 15, 0, 0, tzinfo=TimeZoneInfo('GMT Standard Time', True)), pywintypes.datetime(2020, 7, 15, 0, 0, tzinfo=TimeZoneInfo('GMT Standard Time', True))
    ),
    (
        'var1', 200, 340
    ),
    (
        'var2', 1200, -340
    )
)

I failed to understand what is this format exactly? How can I convert this data to a Pandas data-frame format for further calculation?

Any pointer will be very helpful.

CodePudding user response:

seems like its a tuple of tuples , but if you run this :

print(type(result)) 

you can get a better idea

CodePudding user response:

Given your tuple of tuples format you could use:

import pandas as pd
df = pd.DataFrame(result).set_index(0).T

Output:

        date var1  var2
1 2020-06-15  200  1200
2 2020-07-15  340  -340

CodePudding user response:

You can try

pd.DataFrame(list(result))
  •  Tags:  
  • Related