Code Monkey home page Code Monkey logo

Comments (2)

JBGreisman avatar JBGreisman commented on June 3, 2024

In my mind, this is a behavior that was made by pandas so I hesitate to overload it to change it. For example, this method also doesn't differentiate between np.int64 and pd.Int64Dtype (the nullable pandas int64 implementation):

In [17]: df = pd.DataFrame(np.arange(12).reshape(3, 4),
    ...:                   columns=['A', 'B', 'C', 'D'])
    ...: df["A"] = df["A"].astype(pd.Int64Dtype())

In [18]: df.dtypes
Out[18]: 
A    Int64         <----- Note capitalization
B    int64
C    int64
D    int64
dtype: object

In [19]: df.select_dtypes(pd.Int64Dtype())
Out[19]: 
   A  B   C   D
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11

I do agree that their documentation doesn't make it clear that this operates to return columns based on the underlying numpy dtype though. It is always possible to get this behavior with a list comprehension, so if we do want this sort of method, I would rather implement it as a custom DataSet method rather than overload the DataFrame one. Something like this, but with added support to handle inputting the dtype as str or object:

def select_mtzdtype(self, dtype):
    return self[[k for k in self if isinstance(self.dtypes[k], dtype)]]

from reciprocalspaceship.

kmdalton avatar kmdalton commented on June 3, 2024

I'm totally happy with your proposed solution.

from reciprocalspaceship.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.