有没有办法创建一个包含3个或更多字段的Python内部表?

有没有办法创建一个包含3个或更多字段的Python内部表?,python,dictionary,Python,Dictionary,我被困在如何根据它的类型计算订单上,例如,对于FERT我们有3个,对于ZZ1:1和ROH:0 我想有一个3字段的表格,但我不确定如何尝试这个: #User table, this is where the user orders a material tab_user = { 'USER1': 'MAT1', 'USER2': 'MAT1', 'USER3': 'MAT3', 'USER4': 'MAT4' } #Type table, this determine the mater

我被困在如何根据它的类型计算订单上,例如,对于FERT我们有3个,对于ZZ1:1和ROH:0 我想有一个3字段的表格,但我不确定如何尝试这个:

#User table, this is where the user orders a material
tab_user = {
 'USER1': 'MAT1',
 'USER2': 'MAT1',
 'USER3': 'MAT3',
 'USER4': 'MAT4' }

#Type table, this determine the material type
tab_type = {
 'MAT1': 'FERT',
 'MAT2': 'ROH',
 'MAT3': 'FERT',
 'MAT4': 'ZZZ1' 
}

#this is my code to get what did the user order, this output 'FERT'

print( tab_type.get( tab_user.get( 'USER1' ) ) )

您可以将字典转换为dataframe@chuam2您是如何获得ROH:2的?请使用printCountertab_type.values,其中Couner来自@Gabip抱歉,混淆应为ROH:0@DarrylG谢谢,我用过这个,但仍然不知道如何连接两个表的计数x=collections.Countertab_type.values thank you@Gabip这很有效,我不认为在创建字典时使用列表来引用
# STEP 1 - convert ordered materials to types 
ordered_types = [tab_type.get(m) for m in tab_user.values()]

# STEP 2 - iterate over all types, in order to includes those with zero orders, and count how many times each was ordered based on the first list
output = {t: ordered_types.count(t) for t in tab_type.values()}

print(output) # {'FERT': 3, 'ROH': 0, 'ZZZ1': 1}