I want to calculate conditional probabilites of ratings(\'A\',\'B\',\'C\') in ratings column.
company model rating type
0 ford mustang
first, convert into a pandas dataframe. by doing so, you can take advantage of pandas' groupby methods.
collection = {"company": ["ford", "chevy", "ford", "ford", "ford", "toyota"],
"model": ["mustang", "camaro", "fiesta", "focus", "taurus", "camry"],
"rating": ["A", "B", "C", "A", "B", "B"],
"type": ["coupe", "coupe", "sedan", "sedan", "sedan", "sedan"]}
df = pd.DataFrame(collection)
then, groupby based on events (ie rating).
df_s = df.groupby('rating')['type'].value_counts() / df.groupby('rating')['type'].count()
df_f = df_s.reset_index(name='cpt')
df_f.head() # your conditional probability table