Skip to content

Commit 245d4b0

Browse files
committed
make readme more clear
1 parent 82538c7 commit 245d4b0

File tree

1 file changed

+61
-25
lines changed

1 file changed

+61
-25
lines changed

README.md

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
**The easy way to write your own flavor of Pandas**
33

44
Pandas added an new (simple) API to register accessors with Pandas objects.
5-
This package adds support for registering methods as well.
5+
This package does two things:
6+
1. adds support for registering methods as well.
7+
2. makes each of these functions backwards compatible with older versions of Pandas.
68

7-
*What does this mean?*
9+
***What does this mean?***
810

9-
It's super easy to custom functionality to Pandas DataFrames and Series.
11+
It is now simpler to add custom functionality to Pandas DataFrames and Series.
1012

1113
Import this package. Write a simple python function. Register the function using one of the following decorators.
1214

13-
*Why?*
15+
***Why?***
1416

1517
Pandas is super handy. Its general purpose is to be a "flexible and powerful data analysis/manipulation library".
1618

17-
**Pandas Flavor** allows you to tailor Pandas to specific fields or use cases.
19+
**Pandas Flavor** allows you add functionality that tailors Pandas to specific fields or use cases.
1820

1921
Maybe you want to add new write methods to the Pandas DataFrame? Maybe you want custom plot functionality? Maybe something else?
2022

@@ -37,21 +39,43 @@ class MyFlavor(object):
3739
def __init__(self, data):
3840
self._data
3941

40-
def is_cool(self):
41-
"""Is my accessor cool?"""
42-
return True
42+
def row_by_value(self, col, value):
43+
"""Slice out row from DataFrame by a value."""
44+
return self._data[self._data[col] == value].squeeze()
45+
46+
```
47+
48+
Every dataframe now has this accessor as an attribute.
49+
```python
4350

4451
# DataFrame.
45-
df = DataFrame()
52+
df = DataFrame(data={
53+
"x": [10, 20, 25],
54+
"y": [0, 2, 5]
55+
})
56+
57+
# Print DataFrame
58+
print(df)
59+
60+
# x y
61+
# 0 10 0
62+
# 1 20 2
63+
# 2 25 5
64+
65+
# Access this functionality
66+
df.my_flavor.row_by_value('x', 10)
4667

4768
# Access this functionality
48-
df.my_flavor.is_cool()
49-
# Returns True
50-
True
69+
df.row_by_value('x', 10)
70+
71+
# x 10
72+
# y 0
73+
# Name: 0, dtype: int64
5174
```
5275

53-
To see this in action, check out [pdvega](https://github.com/jakevdp/pdvega)! this
54-
library adds a new plotting accessor for making Vega plots from pandas data.
76+
To see this in action, check out [pdvega](https://github.com/jakevdp/pdvega) and
77+
[PhyloPandas](https://github.com/Zsailer/phylopandas)!
78+
5579

5680
## Register methods
5781

@@ -63,19 +87,31 @@ import pandas as pd
6387
import pandas_flavor as pf
6488

6589
@pf.register_dataframe_method
66-
def is_cool(df):
67-
"""Is my dataframe cool?"""
68-
return True
90+
def row_by_value(df, col, value):
91+
"""Slice out row from DataFrame by a value."""
92+
return df[df[col] == value].squeeze()
93+
94+
```
6995

96+
```python
7097
# DataFrame.
71-
df = DataFrame()
98+
df = DataFrame(data={
99+
"x": [10, 20, 25],
100+
"y": [0, 2, 5]
101+
})
102+
103+
# Print DataFrame
104+
print(df)
105+
106+
# x y
107+
# 0 10 0
108+
# 1 20 2
109+
# 2 25 5
72110

73111
# Access this functionality
74-
df.is_cool()
75-
# Returns True
76-
True
77-
```
112+
df.row_by_value('x', 10)
78113

79-
To see in action, check out [PhyloPandas](https://github.com/Zsailer/phylopandas).
80-
This library adds extra `to_` methods for writing DataFrames to various biological
81-
sequencing file formats.
114+
# x 10
115+
# y 0
116+
# Name: 0, dtype: int64
117+
```

0 commit comments

Comments
 (0)