Giter Site home page Giter Site logo

Comments (3)

asishm avatar asishm commented on June 29, 2024

what about df.T.melt()? you can then either set_index the variable column or drop it altogether.

In [10]: df = pd.DataFrame({0: ['A1', 'A2', 'A3'], 1: ['B1', 'B2', 'B3'], 2: ['C1', 'C2', 'C3']})

In [11]: df
Out[11]:
    0   1   2
0  A1  B1  C1
1  A2  B2  C2
2  A3  B3  C3

In [12]: df.T.melt()
Out[12]:
   variable value
0         0    A1
1         0    B1
2         0    C1
3         1    A2
4         1    B2
5         1    C2
6         2    A3
7         2    B3
8         2    C3

from pandas.

phofl avatar phofl commented on June 29, 2024

Yep agree that this should solve the problem

from pandas.

raybellwaves avatar raybellwaves commented on June 29, 2024

I ended up finding out how to do this in the cudf test suite https://github.com/rapidsai/cudf/blob/branch-24.06/python/cudf/cudf/tests/test_reshape.py#L305 pd.Series(np.vstack(pdf.to_numpy()).reshape((-1,))) which is much faster than df.T.melt()["value"]. Thanks for tip though!

from pandas.

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.