my_dict = {
“key1” : value1,
“key2” : value2,
“key1” : value3
}
my_dict[“title”]
import pandas as pd
avocados_list = [ # Create a list of dictionaries
{"date": "2019-11-03", "small_sold": 10376832, "large_sold": 7835071},
{"date": "2019-11-10", "small_sold": 10717154, "large_sold": 8561348},
]
avocados_2019 = pd.DataFrame(avocados_list) # Convert list into DataFrame
print(avocados_2019)
import pandas as pd
avocados_dict = { # Create a dictionary of lists
"date": ["2019-11-17","2019-12-01"],
"small_sold": [10859987,9291631],
"large_sold": [7674135,6238096]
}
avocados_2019 = pd.DataFrame(avocados_dict) # Convert dictionary into DataFrame
print(avocados_2019)
Store the following tables of data into three DataFrames, add a column to store the month of the sales,
and concatenate the three DataFrames into a single DataFrame.
import pandas as pd
import numpy as np
df1 = {"Quantity Sold": [500, 600],
"Product": ["Apples", "Orange"],
"Unit Price": [1.0, 2.0],
"Month": ["Jan", "Jan"]}
df2 = {"Quantity Sold": [900, 300],
"Product": ["Apples", "Bananas"],
"Unit Price": [0.80, 0.50],
"Month": ["Feb", "Feb"]}
df3 = {"Quantity Sold": [200, 100],
"Product": ["Apples", "Bananas"],
"Unit Price": [0.80, 1.0],
"Month": ["Mar", "Mar"]}
jan = pd.DataFrame(df1)
feb = pd.DataFrame(df2)
mar = pd.DataFrame(df3)
jan.index = [0,1]
feb.index = [2,3]
mar.index = [4,5]
table = pd.concat([jan,feb,mar])
print(table)
Quantity Sold Product Unit Price Month
0 500 Apples 1.0 Jan
1 600 Orange 2.0 Jan
2 900 Apples 0.8 Feb
3 300 Bananas 0.5 Feb
4 200 Apples 0.8 Mar
5 100 Bananas 1.0 Mar