Python How to create a Multi-index dataframe

  • Thread starter Thread starter msn009
  • Start date Start date
  • Tags Tags
    Python
Click For Summary
Generating a multi-index DataFrame in Python can be challenging, particularly when trying to achieve a specific structure. The discussion highlights that while Pandas is effective for handling two-dimensional data, it operates primarily with (i,j) indexing, akin to spreadsheets. Users seeking to implement a three-dimensional (i,j,k) indexing system may find that Pandas is not the ideal tool for this purpose. Instead, leveraging Numpy for 3-D tensor manipulation is recommended, as it provides greater flexibility for such data structures. The conversation emphasizes the limitations of Pandas in this context and suggests alternative approaches for users needing more complex indexing.
msn009
Messages
53
Reaction score
6

Attachments

  • p1.png
    p1.png
    945 bytes · Views: 555
Technology news on Phys.org
I haven't gotten into the weeds of this in while, but I think what you're asking is simply not in Pandas. Pandas is designed, in effect, to be excel spreadsheets via python (with the added capabilities that come with it).

Spreadsheets are fundamentally indexed with (i,j) pairs. There is no third index. (You could try to synthetically creating such a thing via a mapping formula that you come up with though that sounds unpleasant).

If you want to use (i,j,k) indexing, this is 3-D tensor territory that is easy to manipulate via arrays in Numpy. It is not Pandas.
 
  • Like
Likes msn009
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K