美文网首页python
Python中类似于R的tidyverse的包

Python中类似于R的tidyverse的包

作者: 可能性之兽 | 来源:发表于2022-04-17 17:27 被阅读0次

plydata,siuba,dplython

plydata

plydata是python之中很类似与R之中tidyverse的操作的包
用 tidyverse 的方式玩转 Python 数据处理 - 知乎 (zhihu.com)

import numpy as np
import pandas as pd
from plydata import define, query, if_else, ply

# NOTE: query is the equivalent of dplyr's filter but with
#      slightly different python syntax  for the expressions

df = pd.DataFrame({
    'x': [0, 1, 2, 3],
    'y': ['zero', 'one', 'two', 'three']})

df >> define(z='x')
"""
   x      y  z
0  0   zero  0
1  1    one  1
2  2    two  2
3  3  three  3
"""

df >> define(z=if_else('x > 1', 1, 0))
"""
   x      y  z
0  0   zero  0
1  1    one  0
2  2    two  1
3  3  three  1
"""

# You can pass the dataframe as the # first argument
query(df, 'x > 1')  # same as `df >> query('x > 1')`
"""
   x      y
2  2    two
3  3  three
"""

# You can use the ply function instead of the >> operator
ply(df,
    define(z=if_else('x > 1', 1, 0)),
    query('z == 1')
)
"""
    x      y  z
 2  2    two  1
 3  3  three  1
"""
from plotnine import ggplot, aes, geom_line

df = pd.DataFrame({'x': np.linspace(0, 2*np.pi, 500)})
(df
 >> define(y='np.sin(x)')
 >> define(sign=if_else('y >= 0', '"positive"', '"negative"'))
 >> (ggplot(aes('x', 'y'))
     + geom_line(aes(color='sign'), size=1.5))
 )

siuba

machow/siuba: Python library for using dplyr like syntax with pandas and SQL (github.com)

from siuba import group_by, summarize, _
from siuba.data import mtcars

(mtcars
  >> group_by(_.cyl)
  >> summarize(avg_hp = _.hp.mean())
  )

dplython

python 学习之 python 里也能用 dplyr? (qq.com)

Python and Tidyverse (itsalocke.com)

import pandas
from dplython import (DplyFrame, X, diamonds, select, sift, sample_n,
    sample_frac, head, arrange, mutate, group_by, summarize, DelayFunction) 

print(diamondsSmall >> head(4)) 

##    carat      cut  price color clarity  depth  table
## 0   0.23    Ideal    326     E     SI2   61.5   55.0
## 1   0.21  Premium    326     E     SI1   59.8   61.0
## 2   0.23     Good    327     E     VS1   56.9   65.0
## 3   0.29  Premium    334     I     VS2   62.4   58.0

相关文章

  • Python中类似于R的tidyverse的包

    plydatasiuba,dplython plydata plydata是python之中很类似与R之中tidy...

  • D4-R for Data Science

    安装R包 install.packages("tidyverse")数据处理神包tidyverse 加载R包 li...

  • R 数据处理(七)

    前言 在前面的介绍中,我们使用到了 tibbles 这种数据结构。 这是 tidyverse 包定义的类似于 R ...

  • tidyverse包简介

    tidyverse包是对一些具有相同思想,且可以一同工作的R包的收集。载入tidyverse包的时候提醒哪些包是一...

  • R包tidyverse学习

    教程来自: 慕课微生物高通量数据分析入门 学习目标: filter,arrange,mutate,select函数...

  • 水稻GO分析

    1.构建水稻OrgDb包 1.1安装如下依赖: R 包:argparser, tidyverse, formatt...

  • 第三章 使用dplyr进行数据转换

    加载 tidyverse 时,仔细查看输出的冲突信息,它会告诉你 dplyr 覆盖了基础 R 包中的哪些函数。如果...

  • 学习tidyverse(介绍)

    tidyverse是进行数据科学的R包,是为数据科学设计的R软件包的集合。 所有软件包都共享基本的设计理念,语法和...

  • R语言list与Python中的dict

    R中的列表类似于Python中的字典(dictionary)或者Peal中的哈希(hash),但又有差别。其实R有...

  • 数据处理神器tidyverse(1)dplyr

    tidyverse包主要是由一组超级有用的R包(ggplot2,dplyr,purrr,tidyr,readr,t...

网友评论

    本文标题:Python中类似于R的tidyverse的包

    本文链接:https://www.haomeiwen.com/subject/mdylertx.html