How to create a pandas data frame for products and their prices?
I am managing an online store and I have a list of products with their prices. The products and prices are as follows:-
Product: Laptop, Price: $1200
Product: Smartphone, Price $800
Product: Headphones, Price: $150
Product: External Hard Drive, Price 100
My task is to create a pandas data frame to store and organize this product pricing information. What should be the process for me in managing this?
To create a list to pandas dataframe for the given product and prices, firstly, import the pandas library and use the ‘pd. DataFrame()' constructor. Then, define a dictionary with ‘product’ and ‘price’ as given example:-
Import pandas as of
Data = { ‘Product’ : [ ‘Laptop’, ‘Smartphone’, Headphones’, External Hard Drive’],
Df = pd. DataFrame (data)
If you follow the above-mentioned coding structure then this code initializes a data frame with two columns, ‘Product’ and ‘Price’ which will contain the name of specified products and their prices. Now you would have an organized representation of your product and their pricing information in your requested platform of pandas dataFrame named ‘df’. After getting representation you easily manage your products and their pricing.
If you want to gain more knowledge and appropriate techniques about the management of vast databases, join our data scientist course online quickly.