pandas 使用panel 报错 Panel is deprecated and will be removed in a future version.
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
--------------------------------------
上面说的意思:panel在新版本中被xarray的包取代了。可以使用xarray包下的 to_xarray() 方法。
使用方法,例子:
----------官方文档--------------------
pandas.Panel.to_xarray
Panel.to_xarray()[source]
Return an xarray object from the pandas object.
Returns:
xarray.DataArray or xarray.Dataset
Data in the pandas structure converted to Dataset if the object is a DataFrame, or a DataArray if the object is a Series.
See also
DataFrame.to_hdf
Write DataFrame to an HDF5 file.
DataFrame.to_parquet
Write a DataFrame to the binary parquet format.
Notes
See the xarray docs
Examples
>>> df = pd.DataFrame([('falcon', 'bird', 389.0, 2),
... ('parrot', 'bird', 24.0, 2),
... ('lion', 'mammal', 80.5, 4),
... ('monkey', 'mammal', np.nan, 4)],
... columns=['name', 'class', 'max_speed',
... 'num_legs'])
>>> df
name class max_speed num_legs
0 falcon bird 389.0 2
1 parrot bird 24.0 2
2 lion mammal 80.5 4
3 monkey mammal NaN 4
>>> df.to_xarray()
<xarray.Dataset>
Dimensions: (index: 4)
Coordinates:
* index (index) int64 0 1 2 3
Data variables:
name (index) object 'falcon' 'parrot' 'lion' 'monkey'
class (index) object 'bird' 'bird' 'mammal' 'mammal'
max_speed (index) float64 389.0 24.0 80.5 nan
num_legs (index) int64 2 2 4 4
>>> df['max_speed'].to_xarray()
<xarray.DataArray 'max_speed' (index: 4)>
array([389. , 24. , 80.5, nan])
Coordinates:
* index (index) int64 0 1 2 3
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-01',
... '2018-01-02', '2018-01-02'])
>>> df_multiindex = pd.DataFrame({'date': dates,
... 'animal': ['falcon', 'parrot', 'falcon',
... 'parrot'],
... 'speed': [350, 18, 361, 15]}).set_index(['date',
... 'animal'])
>>> df_multiindex
speed
date animal
2018-01-01 falcon 350
parrot 18
2018-01-02 falcon 361
parrot 15
>>> df_multiindex.to_xarray()
<xarray.Dataset>
Dimensions: (animal: 2, date: 2)
Coordinates:
* date (date) datetime64[ns] 2018-01-01 2018-01-02
* animal (animal) object 'falcon' 'parrot'
Data variables:
speed (date, animal) int64 350 18 361 15
import xarray as xr
a = pd.DataFrame({'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]})
b = pd.DataFrame({'a':[11,12,13],'b':[14,15,16],'c':[17,18,19]})
ds = xr.Dataset({1:a, 2:b})
def f(thing):
#print(thing)
return thing.mean()
>>> q = ds.apply(f)
>>> q
<xarray.Dataset>
Dimensions: ()
Data variables:
1 float64 5.0
2 float64 15.0
>>> q[1]
<xarray.DataArray 1 ()>
array(5.)
>>> q[1].values
array(5.)
pandas 使用panel 报错 Panel is deprecated and will be removed in a future version.的更多相关文章
- PHP 5.6 中 Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version
解决方法 找到php.ini 文件, 把always_populate_raw_post_data 修改为-1 就行了. always_populate_raw_post_data=-1
- php5.6 版本出现 Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version 的错误
解决方法是修改php.ini配置: ;always_populate_raw_post_data = -1 把前面的分号去掉 always_populate_raw_post_data = -1 然后 ...
- 关于nodejs DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
const mongoose = require('mongoose') mongoose.connect("mongodb://localhost:27017/study", { ...
- Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the
参考链接 解决方法: 修改 php.ini : always_populate_raw_post_data = -1 PHP 5.6已经废弃了$HTTP_RAW_POST_DATA
- hexo 报错 use_date_for_updated is deprecated...
hexo 报错 use_date_for_updated is deprecated... WARN Deprecated config detected: "use_date_for_up ...
- Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification version
Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification ...
- Php cli模式下执行报错/usr/bin/php: /usr/local/lib/libxml2.so.2: no version information available (required by /usr/bin/php)
centos下php cli模式报错 /usr/bin/php: /usr/local/lib/libxml2.so.2: no version information available (requ ...
- 报错:Method definition shorthands are not supported by current JavaScript version
当你在html中使用调用js中的方法时,会出现这行报错: method definition shorthands are not supported by current JavaScript ve ...
- 解决 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
转载 php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql ext ...
随机推荐
- Asp.Net中virtual、override理解
virtual关键字用于指定属性或方法在派生类中重写.默认情况下,派生类从其基类继承属性和方法,如果继承的属性或方法需要在派生类中有不同的行为,则可以重写它,即可以在派生类中定义该属性或方法的新实现, ...
- Python基础之字典
字典初识 字典的认识 首先,我们来认识一下字典: # 定义一个字典 user_dict = {"name": "zhangsan", "age&quo ...
- Java基础系列--06_抽象类与接口概述
抽象类 (1)如果多个类中存在相同的方法声明,而方法体不一样,我们就可以只提取方法声明. 如果一个方法只有方法声明,没有方法体,那么这个方法必须用抽象修饰. 而一个类中如果有抽象方法,这个类必须定义为 ...
- 《JAVA程序设计》_第九周学习总结
一.学习内容 1.数据库的建立.配置 在官网先下载好MySQL.navicat for MySQL.XAMPP.MySQL-connecter 在XAMPP中点击start开启MySQL 在navic ...
- spring boot 自定义sql分页查询
1.自定义sql查询分页 @Override public <T> Page<T> pageSQL(@Nonnull String sql, @Nonnull Pageable ...
- wifi扫描
获取当前位置的wifi,信道,强度,mac #include "ESP8266WiFi.h" IPAddress apIP(192, 168, 4, 1); void setup( ...
- 360 随身 WiFi3 在 Ubuntu 14.04 下的使用
由于 360 随身 WiFi3 采用 Mediaek 代号 0e8d:760c 的芯片,目前没有官方或第三方 Linux 驱动,所以造成 Linux 用户的诸多困扰. 本文给出一个迂回的解决方案:在 ...
- 文件实时同步(rsync+inotify)
目标服务器:10.11.6.11 源服务器:10.11.6.12 准备条件: 1.关闭selinux: vi /etc/selinux/config #编辑防火墙配置文件 #SELINUX=enfor ...
- LR IP欺骗
一.设置IP欺骗的原因: 1.当某个IP的访问过于频繁,或者访问量过大是,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频率和访问量,以达压力测试的效果 2.某些服务器配置了负载均衡,使用同一个 ...
- git几个必知托管平台
程序员必须知道的几个Git代码托管平台 说到Git代码托管平台,首先推荐的是GitHub,好多好的开源项目都来自GitHub,但是GitHub只能新建公开的Git仓库,私有 仓库要收费,如果你做的 ...