-1

I have the following table

a1b1 a1Eb1 a1b2 a1Eb2 a2b1 a2Eb1 a2b2 a2Eb2 a3b1 a3Eb1 a3b2 a3Eb2
2 20 8 54 3 56 3 67 2 78 7 75
8 30 6 67 6 35 4 56 3 85 6 74
5 54 4 64 7 23 6 48 4 67 4 82
6 65 7 53 8 27 7 35 5 25 3 64
4 34 2 52 4 28 8 27 6 94 2 29

i want to compare the following data:

a1b1 vs a1b2;

then generate arrays containing

a1b1 a1b2 minor a1b1
2 8 20
a1b2 a1b1 minor a1b2
6 8 30

and so for each row of the table

and for each of the following comparisons

  • a2b1 vs a2b2;
  • a3b1 vs a3b2;

I have tried to do it with pandas in python

import pandas as pd
import numpy as np

df = pd.DataFrame ({'a1b1':[2,8,5,6,4],
                    'a1Eb1':[20,30,54,65,34],
                   'a1b2':[8,6,4,7,2],
                    'a1Eb2':[54,67,64,53,52],                   
                   'a2b1':[3,6,7,8,4],
                    'a2Eb1':[56,35,23,27,28],                   
                    'a2b2':[3,4,6,7,8],
                    'a2Eb2':[67,56,48,35,27],
                    'a3b1':[2,3,4,5,6],
                    'a3Eb1':[78,85,67,25,94],    
                   'a3b2':[7,6,4,3,2],
                   'a3Eb3':[75,74,82,64,29],
                   })

but i don't know how to go on.

Output expected

To the first line a1b1<a1b2 then print the following

df1=pd.DataFrame{'a1b1':[2],
                 'a1b2':[8], 
                'a1Eb1':[20]} 

This can be, a DataFrame, a list or any data structure

Ramon
  • 1
  • 1
  • Sorry, what do you mean by "generate vectors"? I'm not very up on linear algebra. – wjandrea Oct 20 '22 at 23:08
  • I meant an array – Ramon Oct 20 '22 at 23:15
  • 2
    can you post the expected output for that sample – Kenan Oct 20 '22 at 23:22
  • 1
    So if `a1b1` is smaller than `a1b2`, you want the `a1Eb1` to be in the new list instead of `a1Eb2` ? – KapJ1coH Oct 20 '22 at 23:39
  • Oh, I see. So then, what have you actually tried? Have you taken a Pandas tutorial? Do you know how to compare columns? Maybe you could use `.mask()` or `.where()`? Secondly, it's not clear what the full output should be for that data. Please make a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). BTW, welcome to Stack Overflow! Start with the [tour]. See [ask] if you want more tips. – wjandrea Oct 20 '22 at 23:51

1 Answers1

0

If you want to display only specific columns of your dataframe you can use the following syntax with [[ and ]] after the name of the dataframe (df), and in between you just add the names of the columns you want to see. It can be 2, 3 or even all of the columns of the dataframes, as long as you separate their names with a comma and put them between quotes.

df[['a1b1','a1b2']] # to display two columns
df[['a2b1','a2b2']]
df[['a3b1','a3b2']] 

to display 3 columns, it could for example be :

df[['a3b1','a3b2','a3b1']]

and so on.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
LucasMiras
  • 36
  • 4
  • 1
    It's worth clarifying that the two sets of brackets mean different things. The outer ones are for indexing and the inner ones make a list. – wjandrea Oct 20 '22 at 23:53