• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

JuliaPy/Pandas.jl: A Julia front-end to Python's Pandas package.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

JuliaPy/Pandas.jl

开源软件地址:

https://github.com/JuliaPy/Pandas.jl

开源编程语言:

Julia 98.5%

开源软件介绍:

Pandas.jl

Pandas.jl logo

CI status

This package provides a Julia interface to the excellent Pandas package. It sticks closely to the Pandas API. One exception is that integer-based indexing is automatically converted from Python's 0-based indexing to Julia's 1-based indexing.

Installation

Simply install the Pandas package using the Julia package manager. From the Julia REPL:

using Pkg
Pkg.add("Pandas")
using Pandas

Which version of the Python Pandas library is used depends on how your installation of PyCall.jl is configured. By default, the Python Pandas library will be automatically downloaded and installed in a mininal Python installation managed by Julia and independent from any other Python distributions on your system.

See the PyCall configuration for instructions on changing this behavior.

Usage

In general, if df is a Pandas object (such as a dataframe or series), then the Python command df.x(y, w=z) becomes x(df, y, w=z) in Julia. df.loc[a,b,c] becomes loc(df)[a,b,c] (same for iloc and ix). Example:

>> using Pandas
>> df = DataFrame(Dict(:age=>[27, 29, 27], :name=>["James", "Jill", "Jake"]))
   age   name
0   27  James
1   29   Jill
2   27   Jake

[3 rows x 2 columns]
>> describe(df)
             age
count   3.000000
mean   27.666667
std     1.154701
min    27.000000
25%    27.000000
50%    27.000000
75%    28.000000
max    29.000000

[8 rows x 1 columns]

df[:age]
0    27
1    29
2    27
Name: age, dtype: int64

>> df2 = DataFrame(Dict(:income=>[45, 101, 87]), index=["Jake", "James", "Jill"])
>> df3 = merge(df, df2, left_on="name", right_index=true)
   age   name  income
0   27  James     101
1   29   Jill      87
2   27   Jake      45

[3 rows x 3 columns]

>> iloc(df3)[1:2, 2:3]
    name  income
0  James     101
1   Jill      87

[2 rows x 2 columns]

>> mean(groupby(df3, "age")) #Or groupby(df, "age3") |> mean
     income
age
27       73
29       87

[2 rows x 1 columns]

>> query(df3, :(income>85)) # or query(df3, "income>85")
   age   name  income
0   27  James     101
1   29   Jill      87

[2 rows x 3 columns]

>> Array(df3)
3x3 Array{Any,2}:
 27  "James"  101
 29  "Jill"    87
 27  "Jake"    45

>> plot(df3)

Input/Output

Example:

df = read_csv("my_csv_file.csv") # Read in a CSV file as a dataframe
to_json(df, "my_json_file.json") # Save a dataframe to disk in JSON format

Performance

Most Pandas operations on medium to large dataframes are very fast, since the overhead of calling into the Python API is small compared to the time spent inside Pandas' highly efficient C implementation.

Setting and getting individual elements of a dataframe or series is slow however, since it requires a round-trip of communication with Python for each operation. Instead, use the values method to get a version of a series or homogeneous dataframe that requires no copying and is as fast to access and write to as a Julia native array. Example:

>> x_series = Series(randn(10000))
>> @time x_series[1]
elapsed time: 0.000121945 seconds (2644 bytes allocated)
>> x_values = values(x_series)
>> @time x_values[1]
elapsed time: 2.041e-6 seconds (64 bytes allocated)
>> x_native = randn(10000)
>> @time x_native[1]
elapsed time: 2.689e-6 seconds (64 bytes allocated)

Changes to the values(...) array propogate back to the underlying series/dataframe:

>> iloc(x_series)[1]
-0.38390854447454037
>> x_values[1] = 10
>> iloc(x_series)[1]
10

Caveats

Panels-related functions are still unwrapped, as well as a few other obscure functions. Note that even if a function is not wrapped explicitly, it can still be called using various methods from PyCall.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
haampie/IncompleteLU.jl: Crout ILU for Julia发布时间:2022-07-09
下一篇:
oscar-system/Singular.jl: Julia package for the Singular library发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap