Informatics Practices

A list stores three dictionaries each storing details, (old price, new price, change). Write a program to create a dataframe from it.

Python Pandas

1 Like

Answer

import pandas as pd
prices = [{'old_price': 10, 'new_price': 12, 'change': 2},
          {'old_price': 20, 'new_price': 18, 'change': -2},
          {'old_price': 30, 'new_price': 35, 'change': 5}]
df = pd.DataFrame(prices)
print(df)

Output

   old_price  new_price  change
0         10         12       2
1         20         18      -2
2         30         35       5

Answered By

2 Likes


Related Questions