panthera icon indicating copy to clipboard operation
panthera copied to clipboard

How do i drop columns?

Open paulakeen opened this issue 4 years ago • 2 comments

Sorry for so basic questions, but how do I drop columns?

I've been trying similar things to this: (-> dataset (pt/drop (pt/subset-cols :columnKeyWord))) (-> dataset (pt/drop (pt/subset-cols [1 2 3 4]))), etc. but get plenty of errors...

In fact, what I miss is a kind of tutorial mapping the pandas methods to the clojure syntax...Does such a thing exist?

paulakeen avatar Nov 22 '20 18:11 paulakeen

No problem!

You can use drop-cols like this to drop columns:

(pt/drop-cols dataset [:your :cols])

Or if you prefer drop -> (pt/drop dataset [:your :cols] {:axis "columns"}) or (pt/drop dataset [:your :cols] {:axis 1})

Here there are some example notebooks, it would be very nice if someone could help checking that everything is still working as expected and expand a little on them. Even in a different format (e.g. no Jupyter or Pink gorilla) would be ok.

The main issue is that the python pandas package is about 43 MB, it's a huge framework with a lot of history and many different ways to perform the same action (as you can see above), moreover there's the problem that when you call drop you're not calling a function in python, but a method on pandas.DataFrame class, and this would be perfectly fine if it stopped there, but with a brief search you can see here that pandas.Series.drop and pandas.Index.drop exist as well.

The panthera dropfunction will work on all those data structures without problems, but if you take a look at the docs you'll see that they all have slight differences in signatures, accepted args, default args, etc. It's impossible for me to know beforehand whether you'll be calling this on a DataFrame, a Series or an Index, so the best way to go is to be always armed with panthera/pytype that returns the python type of the given object, or with series? and data-frame?.

Please let me know if this solves your problem, feel free to ask more questions and I'm always open to any kind of contribution 😄

alanmarazzi avatar Nov 23 '20 08:11 alanmarazzi

Many thanks! It worked. And I found the "mapping" I was looking for.

paulakeen avatar Nov 23 '20 19:11 paulakeen