pandas :在数据框中存储数据框 [英] Pandas: Storing Dataframe in Dataframe

查看:124
本文介绍了 pandas :在数据框中存储数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Pandas并不陌生,目前在尝试将Dataframe插入Dataframe时遇到问题.

I am rather new to Pandas and am currently running into a problem when trying to insert a Dataframe inside a Dataframe.

我想做什么: 我有多个仿真和相应的信号文件,我希望所有这些都放在一个大的DataFrame中.所以我想要一个DataFrame,它具有我所有的模拟参数以及作为嵌套DataFrame的信号.它应该看起来像这样:

What I want to do: I have multiple simulations and corresponding signal files and I want all of them in one big DataFrame. So I want a DataFrame which has all my simulation parameters and also my signals as an nested DataFrame. It should look something like this:

SimName | Date | Parameter 1 | Parameter 2 |  Signal 1 |  Signal 2 |
Name 1  | 123  | XYZ         | XYZ         | DataFrame | DataFrame |
Name 2  | 456  | XYZ         | XYZ         | DataFrame | DataFrame |

其中SimName是我对大型DataFrame的索引,而Signal 1和Signal 2中的每个条目都是单独的DataFrame.

Where SimName is my Index for the big DataFrame and every entry in Signal 1 and Signal 2 is an individuall DataFrame.

我的想法是这样实现:

big_DataFrame['Signal 1'].loc['Name 1']

但这会导致ValueError:

But this results in an ValueError:

索引器与DataFrame不兼容

Incompatible indexer with DataFrame

是否有可能在Pandas中嵌套此DataFrame?

Is it possible to have this nested DataFrames in Pandas?

Nico

推荐答案

ns63sr的答案可以实现为一个类,例如

The 'pointers' referred to at the end of ns63sr's answer could be implemented as a class, e.g...

定义:

class df_holder:
    def __init__(self, df): 
        self.df = df

设置:

df.loc[0,'df_holder'] = df_holder(df)

获取:

df.loc[0].df_holder.df

这篇关于 pandas :在数据框中存储数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆