简体   繁体   English

Pandas 多索引数据框:同一级别的 2 个值

[英]Pandas multiindex dataframe: 2 values on same level

I want to create a multiindex Dataframe in Pandas, however, I have 2 values (string and float), that are unique and to my understanding should be on the highest level.我想在 Pandas 中创建一个多索引数据框,但是,我有 2 个值(字符串和浮点数),它们是唯一的,据我所知应该是最高级别的。 Each of my data sets has one string with a respective (float) value and 4 features that have their respective values in 16 columns.我的每个数据集都有一个带有各自(浮点)值的字符串和 4 个特征,它们在 16 列中具有各自的值。

What is the correct/pythonic way to create such a dataframe?创建此类数据框的正确/pythonic 方法是什么?

1.) Having the value as a level? 1.) 将价值作为一个级别?

2.) Inserting the value 4 times in all columns of the set as its own column? 2.) 在集合的所有列中插入值 4 次作为它自己的列?

3.) Something more elegant I am not aware of? 3.) 我不知道的更优雅的东西? 样本数据

If you think this question is for whatever reasons inappropriate, please let me know in a short comment why and don't just down rate.如果您认为这个问题出于任何原因不合适,请在简短的评论中告诉我原因,不要只是降低率。 Thanks a lot!非常感谢!

I think the best is create DataFrame with:我认为最好的方法是使用以下方法创建DataFrame

Name , Features , value <- MultiIndex with 3 levels Name , Features , value <- 具有 3 个级别的MultiIndex
Pos1 - Pos16 - columns Pos1 - Pos16 - 列

But all depends of what you need do later with data.但一切都取决于您稍后需要对数据做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM