Dany Majard
Feb 28, 2021

--

You can make your own class on top to get the behaviour that you want and then use it wherever you need:

class rTable(pd.DataFrame):    def rloc(self, *args, **kwargs):
output = self.copy()
if len(kwargs) > 0:
for k,v in kwargs.items():
output = output.loc(axis=0)[lambda x: x[k] == v]
if len(args) > 0:
output = output.loc(axis=1)[args]
return output
df = rTable.from_records([
{"who": "the pro",
“able_to”: "add a method to a class"},
{"who": "the noob",
“able_to”: “copy tricks from stackexchange”}])
df.rloc("who", able_to='add a method to a class')

you will see the filtered dataframe com out.

Enjoy!

--

--

Dany Majard
Dany Majard

Written by Dany Majard

Low frequency high quality writing on data tech.

No responses yet