File tree Expand file tree Collapse file tree 1 file changed +106
-0
lines changed Expand file tree Collapse file tree 1 file changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ # pandas-select
2
+
3
+ ![ test status] ( https://github.com/jseabold/pandas-select/workflows/tests/badge.svg )
4
+
5
+ ## What Is It?
6
+
7
+ ` pandas-select ` adds a ` select ` accessor to pandas DataFrames and Series. It's like ` query ` but with the niceties of tab-completion.
8
+
9
+ ## Quickstart
10
+
11
+ ``` python
12
+ In [1 ]: import numpy as np
13
+
14
+ In [2 ]: import pandas as pd
15
+
16
+ In [3 ]: import pandas_select # magic
17
+
18
+ In [4 ]: dta = pd.DataFrame.from_dict({
19
+ ... : ' A' : [' A' , ' B' , ' C' ] * 5 ,
20
+ ... : ' B' : np.arange(1 , 16 ),
21
+ ... : ' C' : pd.date_range(' 2020-01-01' , periods = 15 )
22
+ ... : })
23
+
24
+ In [5 ]: dta.head()
25
+ Out[5 ]:
26
+ A B C
27
+ 0 A 1 2020 - 01 - 01
28
+ 1 B 2 2020 - 01 - 02
29
+ 2 C 3 2020 - 01 - 03
30
+ 3 A 4 2020 - 01 - 04
31
+ 4 B 5 2020 - 01 - 05
32
+
33
+ In [6 ]: dta.select.A == ' B'
34
+ Out[6 ]:
35
+ A B C
36
+ 1 B 2 2020 - 01 - 02
37
+ 4 B 5 2020 - 01 - 05
38
+ 7 B 8 2020 - 01 - 08
39
+ 10 B 11 2020 - 01 - 11
40
+ 13 B 14 2020 - 01 - 14
41
+
42
+ In [7 ]: dta.select.C >= ' 2020-01-03'
43
+ Out[7 ]:
44
+ A B C
45
+ 2 C 3 2020 - 01 - 03
46
+ 3 A 4 2020 - 01 - 04
47
+ 4 B 5 2020 - 01 - 05
48
+ 5 C 6 2020 - 01 - 06
49
+ 6 A 7 2020 - 01 - 07
50
+ 7 B 8 2020 - 01 - 08
51
+ 8 C 9 2020 - 01 - 09
52
+ 9 A 10 2020 - 01 - 10
53
+ 10 B 11 2020 - 01 - 11
54
+ 11 C 12 2020 - 01 - 12
55
+ 12 A 13 2020 - 01 - 13
56
+ 13 B 14 2020 - 01 - 14
57
+ 14 C 15 2020 - 01 - 15
58
+
59
+ In [8 ]: dta.select.A.str.contains(' A' )
60
+ Out[8 ]:
61
+ A B C
62
+ 0 A 1 2020 - 01 - 01
63
+ 3 A 4 2020 - 01 - 04
64
+ 6 A 7 2020 - 01 - 07
65
+ 9 A 10 2020 - 01 - 10
66
+ 12 A 13 2020 - 01 - 13
67
+
68
+ In [9 ]: dta.select.C.dt.is_month_start
69
+ Out[9 ]:
70
+ A B C
71
+ 0 A 1 2020 - 01 - 01
72
+ ```
73
+
74
+ It also works for Series.
75
+
76
+ ``` python
77
+ In [10 ]: dta.A.select == ' A'
78
+ Out[10 ]:
79
+ 0 A
80
+ 3 A
81
+ 6 A
82
+ 9 A
83
+ 12 A
84
+ Name: A, dtype: object
85
+ ```
86
+
87
+ Though the string and datetime accessor APIs are slightly inconsistent. They're available via the select accessor now.
88
+
89
+ ``` python
90
+ In [11 ]: dta.A.select.str.contains(' B' )
91
+ Out[11 ]:
92
+ 1 B
93
+ 4 B
94
+ 7 B
95
+ 10 B
96
+ 13 B
97
+ Name: A, dtype: object
98
+ ```
99
+
100
+ ## Requirements
101
+
102
+ ## Installation
103
+
104
+ ``` bash
105
+ pip install pandas-select
106
+ ```
You can’t perform that action at this time.
0 commit comments