Reputation: 63
The dictionary looks like the following: {'MON_13891_1040_20220606': ['13891', 'MON_13891_1040_20220606', '20220606', '20220612', '20220614', '20220614', '1132.116664', '15378.55', '19.633334', '426.65', '0', '0', '0', '0'], 'MON_16440_9999_20220606': ['16440', 'MON_16440_9999_20220606', '20220606', '20220612', '20220614', '20220614', '619.92', '9621.64', '13.0', '304.14', '0.0', '0.0', '7.0', '105.0']}
I want to exclude the keys and make a dataframe with rows as values of the keys. How would I go about appending the values as rows to a dataframe with the column names set as follows for the dataframe:
import pandas as pd
#the dictionary is called full_data
header = ["Group", "PeriodIdentifier", "WeekIdentifier", "Start", "End", "PostedDate", "ApprovedDate", "RegularTotalHours", "RegularTotalDollars", "OverTimeTotalHours", "OverTimeTotalDollars","DoubleTimeTotalHours", "DoubleTimeTotalDollars", "MiscPayTotalHours", "MiscPayTotalDollars"]
df1 = pd.Dataframe(columns=header)
Upvotes: 0
Views: 1124
Reputation: 60
This should do it
import pandas as pd
mydict = {'MON_13891_1040_20220606': ['13891', 'MON_13891_1040_20220606', '20220606', '20220612', '20220614', '20220614', '1132.116664', '15378.55', '19.633334', '426.65', '0', '0', '0', '0'], 'MON_16440_9999_20220606': ['16440', 'MON_16440_9999_20220606', '20220606', '20220612', '20220614', '20220614', '619.92', '9621.64', '13.0', '304.14', '0.0', '0.0', '7.0', '105.0']}
header = ["PeriodIdentifier", "WeekIdentifier", "Start", "End", "PostedDate", "ApprovedDate", "RegularTotalHours", "RegularTotalDollars", "OverTimeTotalHours", "OverTimeTotalDollars","DoubleTimeTotalHours", "DoubleTimeTotalDollars", "MiscPayTotalHours", "MiscPayTotalDollars"]
df1 = pd.DataFrame(mydict.values(), columns = header, index = mydict.keys())
Upvotes: 2