dimanche 15 août 2021

Filter and select random rows

I am not familiar with pandas and openpyxl package in Python but was just wondering if it is possible to select random, filtered rows from an excel file and save the output in a separate excel file ?

For example: The data below represents what is in my excel file and what I would like to do is that:

A  B  C  D  E  F   G
1  x  -8  x  x  x  10/12/2019
3  x  +9  x  x  x  28/12/2019
4  x  +2  x  x  x  12/12/2019
1  x  -2  x  x  x  15/12/2019
4  x  -9  x  x  x  19/12/2019
5  x  -1  x  x  x  25/12/2019
  1. Filter to only negative values in column C ("-ve")
  2. Filter to only items (Column G) dated from 15/12/2019 onwards
  3. Randomly select samples (for example, 2) from this filtered list
  4. Save the 2 randomly selected samples in a new excel file, with the headers (A,B,C,D,E,F,G)

Is there any way i could do this ? Potentially, I will be using the script for well over 20 times.

Thank you !




Aucun commentaire:

Enregistrer un commentaire