i have a dataset that i read in with pd.read_excel
Block Con
1 100
1 100
1 100
1 33
1 33
1 33
2 100
2 100
2 100
2 33
2 33
2 33
...
there are a total of 10 'block's, each 'block' has 2 types of 'con': 100 and 33. how can i iterate through the 'Block' column so that for each 'block' it prints out the 2 types of 'con': 100 and 33
desire output:
1 100
33
2 100
33
my code:
for b in data.Block:
for c in data.Con:
print(c)
but it prints out all of the con for each row of block.
Use drop_duplicates:
In [11]: df
Out[11]:
Block Con
0 1 100
1 1 100
2 1 100
3 1 33
4 1 33
5 1 33
6 2 100
7 2 100
8 2 100
9 2 33
10 2 33
11 2 33
In [12]: df.drop_duplicates()
Out[12]:
Block Con
0 1 100
3 1 33
6 2 100
9 2 33
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With