1

I have a python dictionary:

{'data': {'count': 141,
          'telemetries': [{'date': '2021-03-01 06:01:52',
                           'totalActivePower': 0.0,
                           'dcVoltage': None,
                           'powerLimit': 100.0,
                           'totalEnergy': 7175210.0,
                           'temperature': 3.591,
                           'inverterMode': 'SLEEPING',
                           'operationMode': 0,
                           'L1Data': {'acCurrent': 0.0,
                                      'acVoltage': 242.78,
                                      'acFrequency': 59.9746,
                                      'apparentPower': 0.0,
                                      'activePower': 0.0,
                                      'reactivePower': 0.0,
                                      'cosPhi': 0.0}},
                          {'date': '2021-03-01 06:41:52',
                           'totalActivePower': 0.0,
                           'dcVoltage': 429.019,
                           'groundFaultResistance': 11000.0,
                           'powerLimit': 100.0,
                           'totalEnergy': 7175210.0,
                           'temperature': 4.60093,
                           'inverterMode': 'THROTTLED',
                           'operationMode': 0,
                           'L1Data': {'acCurrent': 0.0,
                                      'acVoltage': 241.453,
                                      'acFrequency': 59.9624,
                                      'apparentPower': 0.0,
                                      'activePower': 0.0,
                                      'reactivePower': 0.0,
                                      'cosPhi': 0.0}}]}}

that I can get into a pandas Dataframe like:

Example DataFrame

but I would like the 'L1Data' data to be broken out into individual columns like the rest of the pandas DataFrame. How do I dot that?

Thanks for the help

6
  • Your dictionary is incomplete. Commented Mar 28, 2021 at 17:22
  • then why can I get a Dataframe like the image above? How do I split the 'L1Data' column into individual columns? Commented Mar 28, 2021 at 17:25
  • You didn't realize that ellipsis (...) were in your data making it impossible for me to copy and paste. Commented Mar 28, 2021 at 17:27
  • What is the line of code you are using to get it into a dataframe? Commented Mar 28, 2021 at 17:28
  • The whole set of data is large, wanted to share just a portion of it sorry of the ellipsis at the end. Commented Mar 28, 2021 at 17:29

2 Answers 2

1

pd.json_normalize

pd.json_normalize(dat['data']['telemetries'])

                  date  totalActivePower  dcVoltage  powerLimit  totalEnergy  temperature inverterMode  operationMode  L1Data.acCurrent  L1Data.acVoltage  L1Data.acFrequency  L1Data.apparentPower  L1Data.activePower  L1Data.reactivePower  L1Data.cosPhi  groundFaultResistance
0  2021-03-01 06:01:52               0.0        NaN       100.0    7175210.0      3.59100     SLEEPING              0               0.0           242.780             59.9746                   0.0                 0.0                   0.0            0.0                    NaN
1  2021-03-01 06:41:52               0.0    429.019       100.0    7175210.0      4.60093    THROTTLED              0               0.0           241.453             59.9624                   0.0                 0.0                   0.0            0.0                11000.0
Sign up to request clarification or add additional context in comments.

Comments

0

Try: df.L1Data.str.split(",", expand=True)

1 Comment

a = temp_df1.L1Data.str.split(',', expand=True) a.head(5) this is returning nans

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.