I have a dictionary('voltage') with multiple excel sheets as items in it. I want to extract 20% of the total number of sheets from the original dictionary and store them in a separate dictionary('sample'). I have written the following code.
data = pd.ExcelFile('filename.xlsx')
voltage = {}
for sheet in data.sheet_names:
voltage[sheet] = pd.read_excel(data, sheet)
sample = dict(random.sample(voltage.items(), int(len(voltage) * 20 / 100)))
With the above code, I am able to get 20% of the total number of sheets but these sheets are not being removed from the original dictionary. I want to remove those randomly selected 20% sheets to be deleted from the original dictionary and to be stored in the new dictionary. Can anyone help me with this??
Aucun commentaire:
Enregistrer un commentaire