Python Use fitter Then you will get an average loc, How can I output this mean loc
The two methods , I just learned it secretly
# Character decomposition method import re # Import re# Suppose this is yours filter The dictionary after dict_goal = {
'lognorm': {
's': 0.17754071946201297, 'loc': 0.04714525287344861, 'scale': 0.0027848854527136027}}def get_loc(dict_you_want): # Write a small method , The entry is the dictionary you want to deal with res = float(re.findall(r"\'loc\': \d*.\d*", str(dict_you_want), re.DOTALL)[0].strip("'loc': ")) # float() Is the character str Convert to float, That is, the number with decimal point # re.findall( The characteristics of the content you are looking for , In which strings ,re.DOTALL) re.DOTALL Indicates that each character to be read includes \n etc. # among \' Indicates English single quotation marks \d Represents numeric characters . Means any character * It means to follow 0 To infinite congeners , such as \d* The length is 0 To infinite number string , It can be used to find 0.04714525287344861 # strip() You can remove the specified characters at both ends , For example, we can remove loc Mark , Just pure numbers return res # The export is extracted float The number way_A = get_loc(dict_goal)# print(way_A) The result is that 0.04714525287344861# The normal way way_B = dict_goal['lognorm']['loc'] # filter after , The result is a big dictionary with a small dictionary , Then let's set two key Can also extract # print(way_B) The result is that 0.04714525287344861