将数据帧分配给Pandas中的Panel [英] assigning dataframe to Panel in Pandas

查看:67
本文介绍了将数据帧分配给Pandas中的Panel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算从目录中读取CSV文件列表,并将其作为一系列数据框分配给面板.但是,Panel似乎并没有从read_csv()中获得回报.我正在使用Pandas 0.11和NumPy 1.7.1.这是我到目前为止所做的摘要:

I intend to read from a directory a list of CSV files and assign them to a Panel as a series of dataframes. But the Panel doesn't seem to taking the return from the read_csv(). I am using Pandas 0.11 and NumPy 1.7.1. Here's a snippet of what I have done so far:

dp = pd.Panel({})    
j = 0
for csv in csv_list:
    dp[j] = pd.read_csv(csv, index_col=key, sep=delim_list[j])
    j += 1

但是从空闲状态来看,它表明:

But from idle it shows that:

>>> dp[0]
Empty DataFrame
Columns: []
Index: []

我在做什么错了?

推荐答案

确保您的csv读入正确

Make sure that your csv is reading in correctly

使dp成为字典,然后在最后创建面板

make dp a dict, then create the Panel at the end

In [1]: p = pd.Panel(dict([ (i,DataFrame(randn(3,2))) for i in range(4) ]))

In [2]: p[0]
Out[2]: 
          0         1
0 -1.400715 -1.283452
1 -0.237714  0.677903
2  0.295015 -0.536786

In [3]: p
Out[3]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 4 (items) x 3 (major_axis) x 2 (minor_axis)
Items axis: 0 to 3
Major_axis axis: 0 to 2
Minor_axis axis: 0 to 1

这篇关于将数据帧分配给Pandas中的Panel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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