2

I have this dictionary record randomly generated looking like this (could have potentially more record)

{'Device_ID': 4, 'Temp1': 58.685912388818124, 'Temp2': 74.55450362769994, 'Temp3': 29.342956194409062, 'Temp_Ambient': 22.89076035200238, 'Time': 19}
{'Device_ID': 6, 'Temp1': 48.75315131444877, 'Temp2': 63.62846644589365, 'Temp3': 24.376575657224386, 'Temp_Ambient': 22.540969718435385, 'Time': 15}

I would like the keys: Device ID, Temp1, Temp2, Temp3, Time, Temp_Ambient to be columns of the dataframe

when i try:

df = pd.DataFrame([record], columns=record.keys())

it only shows one row of data.

1 Answer 1

3

Assuming it's a list of dicts:

lod = [{'Device_ID': 4, 'Temp1': 58.685912388818124, 'Temp2': 74.55450362769994, 'Temp3': 29.342956194409062, 'Temp_Ambient': 22.89076035200238, 'Time': 19},
{'Device_ID': 6, 'Temp1': 48.75315131444877, 'Temp2': 63.62846644589365, 'Temp3': 24.376575657224386, 'Temp_Ambient': 22.540969718435385, 'Time': 15}]
df = pd.DataFrame(lod)
print(df)

Output:

   Device_ID      Temp1      Temp2      Temp3  Temp_Ambient  Time
0          4  58.685912  74.554504  29.342956      22.89076    19
1          6  48.753151  63.628466  24.376576      22.54097    15
Sign up to request clarification or add additional context in comments.

Comments

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.