Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

python - How do I filter on the dictionary values data within a dataframe?

I have created a class Settings2:

def __init__(self,path):
    self.data = self.load(path)
    self.path = path
      
def load(self,path):
    if path.endswith('.xlsx'):
        print ("This is a valid file path")
    else:
        raise Exception("This is not a valid file path")
    #LOAD WORKBOOK
    workbook = load_workbook(filename=path)
    # CREATE THE DICTIONARY TO HOLD DATAFRAMES
",
    data_dict = {}
    # GO THROUGH SHEETS, STORING SHEETNAME AND DATAFRAME
",
    for sheet in workbook.sheetnames:
        data_dict[sheet] = pd.read_excel(path, sheet_name=sheet)
    return data_dict`

As part of this class I have a get() method:

    def get(self,path,sheet):
        print (list(filter(lambda path:str(path).startswith(sheet),s2.data.keys())))

Which when I input:s2.get('F:filepathfile.xlsx',"sheet_name_dummy")

Will output: ['dummy_RULE', 'dummy_SCORE'] etc

I want to be able to retrieve the data within those individal dataframes, if I filter on the first 3 letters of the column names of the dataframes for example.

Currently, my code below isn't returning anything from the sheet where I know there are RULE_ID values that contain the dummy_rule_name:

def getvalues(self,path,sheet):
        print (list(map(lambda path:(path).query("RULE_ID == 'dummy_rule_name'"),s2.data.values())))

Any help would be much appreciated thanks

question from:https://stackoverflow.com/questions/66061812/how-do-i-filter-on-the-dictionary-values-data-within-a-dataframe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...