Skip to content

Commit 80dba61

Browse files
committed
Start to clean up docs in preparation for next release
1 parent e5d98b6 commit 80dba61

File tree

4 files changed

+124
-65
lines changed

4 files changed

+124
-65
lines changed

AUTHORS.rst

+13-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
Christopher Clarke <[email protected]>
1+
Django-pandas is written and maintained by Christopher Clarke and
2+
various contributors:
3+
4+
Development Lead
5+
````````````````
6+
7+
- Christopher Clarke <[email protected]>
8+
9+
Contributions
10+
``````````````
11+
- Bertrand Bordage <[email protected]>
12+
- Yuval Langer <http://yuvallanger.github.io>
13+

CONTRIBUTING.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Please:
1212
- Write `good commit messages`_.
1313
- Ideally, squash_ your commits, i.e. make your pull requests just one commit.
1414

15-
Thank you for considering to contribute to “pem”!
15+
Thank you for considering to contribute to ``django-pandas``.
1616

1717

1818
.. _`squash`: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

django_pandas/managers.py

+109-63
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,40 @@ def to_pivot_table(self, fieldnames=(), verbose=True,
1414
as a DataFrame
1515
Parameters
1616
----------
17-
fieldnames: The model field names to utilise in creating the frame.
18-
to span a relationship, just use the field name of related
19-
fields across models, separated by double underscores,
20-
values : column to aggregate, optional
21-
rows : list of column names or arrays to group on
22-
Keys to group on the x-axis of the pivot table
23-
cols : list of column names or arrays to group on
24-
Keys to group on the y-axis of the pivot table
25-
aggfunc : function, default numpy.mean, or list of functions
26-
If list of functions passed, the resulting pivot table will have
27-
hierarchical columns whose top level are the function names
28-
(inferred from the function objects themselves)
29-
fill_value : scalar, default None
30-
Value to replace missing values with
31-
margins : boolean, default False
32-
Add all row / columns (e.g. for subtotal / grand totals)
33-
dropna : boolean, default True
34-
Do not include columns whose entries are all NaN
17+
fieldnames: The model field names(columns) to utilise in creating
18+
the DataFrame. You can span a relationships in the usual
19+
Django ORM way by using the foreign key field name
20+
separated by double underscores and refer to a field
21+
in a related model.
22+
23+
values: The field to use to calculate the values to aggregate.
24+
25+
rows: The list of field names to group on
26+
Keys to group on the x-axis of the pivot table
27+
28+
cols: The list of column names or arrays to group on
29+
Keys to group on the y-axis of the pivot table
30+
31+
aggfunc: How to arregate the values. By default this would be
32+
``numpy.mean``. A list of aggregates functions can be passed
33+
In this case the resulting pivot table will have
34+
hierarchical columns whose top level are the function names
35+
(inferred from the function objects themselves)
36+
37+
fill_value: A scalar value to replace the missing values with
38+
39+
margins: Boolean, default False Add all row / columns
40+
(e.g. for subtotal / grand totals)
41+
42+
dropna: Boolean, default True.
43+
Do not include columns whose entries are all NaN
44+
45+
verbose: If this is ``True`` then populate the DataFrame with the
46+
human readable versions for foreign key fields else
47+
the primary keys values will be used for foreign key fields.
48+
The human readable version of the foreign key field is
49+
defined in the ``__unicode__`` or ``__str__``
50+
methods of the related class definition
3551
"""
3652
df = self.to_dataframe(fieldnames, verbose=verbose)
3753

@@ -44,38 +60,70 @@ def to_timeseries(self, fieldnames=(), verbose=True,
4460
values=None, pivot_columns=None, freq=None,
4561
rs_kwargs=None):
4662
"""
47-
A convenience method for creating a time series i.e the
48-
DataFrame index is instance of a DateTime or PeriodIndex
63+
A convenience method for creating a time series DataFrame i.e the
64+
DataFrame index will be an instance of DateTime or PeriodIndex
4965
5066
Parameters
5167
----------
5268
53-
fieldnames: The model field names to utilise in creating the frame.
54-
to span a relationship, just use the field name of related
55-
fields across models, separated by double underscores,
56-
57-
index: specify the field to use for the index. If the index
58-
field is not in the field list it will be appended. This
59-
is mandatory.
60-
61-
storage: Specify if the queryset uses the `wide` or `long` format
62-
for data.
63-
64-
pivot_column: Required once the you specify `long` format
65-
storage. This could either be a list or string identifying
66-
the field name or combination of field. If the pivot_column
67-
is a single column then the unique values in this column become
68-
a new columns in the DataFrame
69-
If the pivot column is a list the values in these columns are
70-
concatenated (using the '-' as a separator)
71-
and these values are used for the new timeseries columns
72-
73-
values: Also required if you utilize the `long` storage the
74-
values column name is use for populating new frame values
75-
76-
freq: the offset string or object representing a target conversion
77-
78-
rs_kwargs: Arguments based on pandas.DataFrame.resample
69+
fieldnames: The model field names(columns) to utilise in creating
70+
the DataFrame. You can span a relationships in the usual
71+
Django ORM way by using the foreign key field name
72+
separated by double underscores and refer to a field
73+
in a related model.
74+
75+
index: specify the field to use for the index. If the index
76+
field is not in fieldnames it will be appended. This
77+
is mandatory for timeseries.
78+
79+
storage: Specify if the queryset uses the
80+
``wide`` format
81+
82+
date | col1| col2| col3|
83+
-----------|------|-----|-----|
84+
2001-01-01-| 100.5| 23.3| 2.2|
85+
2001-02-01-| 106.3| 17.0| 4.6|
86+
2001-03-01-| 111.7| 11.1| 0.7|
87+
88+
or the `long` format.
89+
90+
date |values| names|
91+
-----------|------|------|
92+
2001-01-01-| 100.5| col1|
93+
2001-02-01-| 106.3| col1|
94+
2001-03-01-| 111.7| col1|
95+
2001-01-01-| 23.3| col2|
96+
2001-02-01-| 17.0| col2|
97+
2001-01-01-| 23.3| col2|
98+
2001-02-01-| 2.2| col3|
99+
2001-03-01-| 4.6| col3|
100+
2001-03-01-| 0.7| col3|
101+
102+
103+
pivot_column: Required once the you specify `long` format
104+
storage. This could either be a list or string
105+
identifying the field name or combination of field.
106+
If the pivot_column is a single column then the
107+
unique values in this column become a new columns in
108+
the DataFrame If the pivot column is a list the values
109+
in these columns are concatenated (using the '-'
110+
as a separator) and these values are used for the new
111+
timeseries columns
112+
113+
values: Also required if you utilize the `long` storage the
114+
values column name is use for populating new frame values
115+
116+
freq: The offset string or object representing a target conversion
117+
118+
rs_kwargs: A dictonary of keyword arguments based on the
119+
``pandas.DataFrame.resample`` method
120+
121+
verbose: If this is ``True`` then populate the DataFrame with the
122+
human readable versions of any foreign key fields else use
123+
the primary keys values.
124+
The human readable version of the foreign key field is
125+
defined in the ``__unicode__`` or ``__str__``
126+
methods of the related class definition
79127
"""
80128
if index is None:
81129
raise AssertionError('You must supply an index field')
@@ -114,40 +162,38 @@ def to_timeseries(self, fieldnames=(), verbose=True,
114162

115163
return df
116164

117-
def to_dataframe(self, fieldnames=(), verbose=True, index=None, fill_na=None,
165+
def to_dataframe(self, fieldnames=(), verbose=True, index=None,
118166
coerce_float=False):
119167
"""
120168
Returns a DataFrame from the queryset
121169
122170
Paramaters
123171
-----------
124172
125-
fieldnames: The model fields to utilise in creating the frame.
126-
to span a relationship, just use the field name of related
127-
fields across models, separated by double underscores,
173+
fieldnames: The model field names(columns) to utilise in creating
174+
the DataFrame. You can span a relationships in the usual
175+
Django ORM way by using the foreign key field name
176+
separated by double underscores and refer to a field
177+
in a related model.
128178
129179
130-
index: specify the field to use for the index. If the index
131-
field is not in the field list it will be appended
180+
index: specify the field to use for the index. If the index
181+
field is not in fieldnames it will be appended. This
182+
is mandatory for timeseries.
132183
133-
fill_na: fill in missing observations using one of the following
134-
this is a string specifying a pandas fill method
135-
{'backfill, 'bill', 'pad', 'ffill'} or a scalar value
184+
verbose: If this is ``True`` then populate the DataFrame with the
185+
human readable versions for foreign key fields else
186+
the primary keys values will be used for foreign key fields.
187+
The human readable version of the foreign key field is
188+
defined in the ``__unicode__`` or ``__str__``
189+
methods of the related class definition
136190
137-
coerce_float: Attempt to convert the numeric non-string data
138-
like object, decimal etc. to float if possible
139191
"""
140192

141193
df = read_frame(self, fieldnames=fieldnames, verbose=verbose,
142194
index_col=index,
143195
coerce_float=coerce_float)
144196

145-
if fill_na is not None:
146-
if fill_na not in ('backfill', 'bfill', 'pad', 'ffill'):
147-
df = df.fillna(value=fill_na)
148-
else:
149-
df = df.fillna(method=fill_na)
150-
151197
return df
152198

153199

django_pandas/tests/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MyModelChoice(models.Model):
2727
]
2828
col1 = models.IntegerField(choices=CHOICES)
2929
col2 = models.FloatField(null=True)
30+
objects = DataFrameManager()
3031

3132

3233
class DataFrame(models.Model):

0 commit comments

Comments
 (0)