jeudi 7 mars 2019

get a random item from a group of rows in a xlsx file in python

I have a xlsx file, for example:

A  B  C  D  E  F  G
1  5  2  7  0  1  8
3  4  0  7  8  5  9
4  2  9  7  0  6  2
1  6  3  2  8  8  0
4  3  5  2  5  7  9
5  2  3  2  6  9  1

being my values (that are actually on an excel file). I nedd to get random rows of it, but separeted for column D values.

You can note that column D has values that are 7 and values that are 2.

I need to get 1 random row of all the rows that have 7 on column D and 1 random row of all the rows that have 2 on column D.

And put the results on another xlsx file.

My expected output needs to be the content of line 0, 1 or 2 and the content of line 3, 4 or 5.

Can someone help me with that? Thanks!




Aucun commentaire:

Enregistrer un commentaire