Skip to content

Commit 7c0db07

Browse files
committed
Create polars.md
1 parent 0611438 commit 7c0db07

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## Polars 快速开始
2+
3+
从一定程度上说、`pandas` 可以完美的应用于我们的日常办公和数据处理。(Pandas 发布于 2008 年、至今14年了神奇吧、使用 Python、Cython 和 C 编写的)
4+
5+
比较遗憾的是 `pandas` 对于大数据量的读写操作竟有些吃力、性能和处理速度往往不如人意、所以北极熊来了。
6+
7+
`polars` 是通过 `Rust` 编写的一个库,`polars` 的内存模型是基于 `Apache Arrow`
8+
9+
`polars` 在很大程度上借鉴了 `pandas` 的语法风格、所以熟悉 `pandas` 的用户可直接上手。
10+
11+
12+
## 安装
13+
14+
```shell
15+
pip install polars
16+
```
17+
18+
```python
19+
import polars as pl
20+
pl.__version__ # 0.13.4
21+
```
22+
23+
## 基本数据结构
24+
25+
构建 DataFrame
26+
27+
```python
28+
import polars as pl
29+
import numpy as np
30+
31+
np.random.seed(12)
32+
33+
df = pl.DataFrame(
34+
{
35+
"nrs": [1, 2, 3, None, 5],
36+
"names": ["foo", "ham", "spam", "egg", None],
37+
"random": np.random.rand(5),
38+
"groups": ["A", "A", "B", "C", "B"],
39+
}
40+
)
41+
print(df)
42+
```
43+
44+
45+
46+
```python
47+
```
48+
49+
50+
## 基本的读取和写入
51+
52+
### 数据读取
53+
54+
```python
55+
```
56+
57+
```python
58+
```
59+
60+
61+
如果想要把表格快速转换为markdown和latex语言,可以使用to_markdown和to_latex函数,此处需要安装tabulate包。
62+
63+
```shell
64+
pip install tabulate
65+
```
66+
67+
这里笔者比较提前安装完毕了。
68+
69+
| | city | collects | comments | pub_time | title | update_time | username |
70+
|---:|:-------|-----------:|-----------:|:-----------------|:-----------------------------------------|:--------------------|:------------------|
71+
| 0 | 成都 | 998 | 10 | 2020-06-11 14:26 | 成都重庆旅游攻略|超详细,假期出游必备 | 2021-08-26 16:47:27 | Starman |
72+
| 1 | 成都 | 160 | 57 | 2021-08-11 20:34 | 夏日出行|超详细的成都融创乐园攻略! | 2021-08-26 16:47:31 | 荔枝太郎 |
73+
| 2 | 成都 | 2127 | 137 | 2020-06-11 19:49 | 成都夜市最强攻略合集,总有一个能打动你 | 2021-08-26 16:47:36 | 金克丝 |
74+
| 3 | 成都 | 2403 | 152 | 2019-08-16 21:49 | 五一小长假怎么花1500元玩转重庆和成都👇 | 2021-08-26 16:47:40 | 旅拍摄影师小周周 |
75+
| 4 | 成都 | 568 | 53 | 2021-07-27 17:21 | 重庆成都5天4夜一站式旅游攻略🔥人均1000 | 2021-08-26 16:47:44 | 不眠的小嗷娇 |
76+
| 5 | 成都 | 1302 | 20 | 2021-04-26 12:31 | 2021年成都私藏攻略㊙️五一小长假旅游必看 | 2021-08-26 16:47:48 | 150斤少女 |
77+
| 6 | 成都 | 700 | 7 | 2021-04-25 08:40 | 成都三天两晚保姆级攻略🔵人均1000💰快收藏 | 2021-08-26 16:47:52 | 雪琪小仙女 |
78+
| 7 | 成都 | 564 | 36 | 2021-03-25 23:04 | 成都必去的12个景点门票攻略~ | 2021-08-26 16:47:57 | 雪琪小仙女 |
79+
| 8 | 成都 | 3190 | 122 | 2021-04-21 16:59 | 成都旅游攻略|网红美食避坑|本地人推荐‼️ | 2021-08-26 16:48:01 | 破产兄弟BrokeBros |
80+
| 9 | 成都 | 963 | 39 | 2021-06-11 11:35 | 成都旅游‼️本地人整理三天两夜吃喝全攻略 | 2021-08-26 16:48:05 | 150斤少女 |
81+
82+
> 如表格格式有错乱、笔者推荐使用 jupyter notebook
83+
84+
85+
### 数据写入
86+
87+
```python
88+
```
89+

0 commit comments

Comments
 (0)