@@ -29,7 +29,7 @@ a default integer index:
29
29
s = pd.Series([1 , 3 , 5 , np.nan, 6 , 8 ])
30
30
s
31
31
32
- Creating a :class: `DataFrame ` by passing a NumPy array, with a datetime index
32
+ Creating a :class: `DataFrame ` by passing a NumPy array, with a datetime index using :func: ` date_range `
33
33
and labeled columns:
34
34
35
35
.. ipython :: python
@@ -93,14 +93,15 @@ Viewing data
93
93
94
94
See the :ref: `Basics section <basics >`.
95
95
96
- Here is how to view the top and bottom rows of the frame:
96
+ Use :meth: `DataFrame.head ` and :meth: `DataFrame.tail ` to view the top and bottom rows of the frame
97
+ respectively:
97
98
98
99
.. ipython :: python
99
100
100
101
df.head()
101
102
df.tail(3 )
102
103
103
- Display the index, columns:
104
+ Display the :attr: ` DataFrame. index` or :attr: ` DataFrame. columns` :
104
105
105
106
.. ipython :: python
106
107
@@ -116,7 +117,7 @@ while pandas DataFrames have one dtype per column**. When you call
116
117
of the dtypes in the DataFrame. This may end up being ``object ``, which requires
117
118
casting every value to a Python object.
118
119
119
- For ``df ``, our :class: `DataFrame ` of all floating-point values,
120
+ For ``df ``, our :class: `DataFrame ` of all floating-point values, and
120
121
:meth: `DataFrame.to_numpy ` is fast and doesn't require copying data:
121
122
122
123
.. ipython :: python
@@ -147,13 +148,13 @@ Transposing your data:
147
148
148
149
df.T
149
150
150
- Sorting by an axis:
151
+ :meth: ` DataFrame.sort_index ` sorts by an axis:
151
152
152
153
.. ipython :: python
153
154
154
155
df.sort_index(axis = 1 , ascending = False )
155
156
156
- Sorting by values:
157
+ :meth: ` DataFrame.sort_values ` sorts by values:
157
158
158
159
.. ipython :: python
159
160
@@ -166,8 +167,8 @@ Selection
166
167
167
168
While standard Python / NumPy expressions for selecting and setting are
168
169
intuitive and come in handy for interactive work, for production code, we
169
- recommend the optimized pandas data access methods, `` .at ``, `` .iat ` `,
170
- `` .loc `` and `` .iloc ` `.
170
+ recommend the optimized pandas data access methods, :meth: ` DataFrame .at `, :meth: ` DataFrame .iat `,
171
+ :meth: ` DataFrame .loc ` and :meth: ` DataFrame .iloc `.
171
172
172
173
See the indexing documentation :ref: `Indexing and Selecting Data <indexing >` and :ref: `MultiIndex / Advanced Indexing <advanced >`.
173
174
@@ -181,7 +182,7 @@ equivalent to ``df.A``:
181
182
182
183
df[" A" ]
183
184
184
- Selecting via ``[] ``, which slices the rows:
185
+ Selecting via ``[] `` (`` __getitem__ ``) , which slices the rows:
185
186
186
187
.. ipython :: python
187
188
@@ -191,7 +192,7 @@ Selecting via ``[]``, which slices the rows:
191
192
Selection by label
192
193
~~~~~~~~~~~~~~~~~~
193
194
194
- See more in :ref: `Selection by Label <indexing.label >`.
195
+ See more in :ref: `Selection by Label <indexing.label >` using :meth: ` DataFrame.loc ` or :meth: ` DataFrame.at ` .
195
196
196
197
For getting a cross section using a label:
197
198
@@ -232,7 +233,7 @@ For getting fast access to a scalar (equivalent to the prior method):
232
233
Selection by position
233
234
~~~~~~~~~~~~~~~~~~~~~
234
235
235
- See more in :ref: `Selection by Position <indexing.integer >`.
236
+ See more in :ref: `Selection by Position <indexing.integer >` using :meth: ` DataFrame.iloc ` or :meth: ` DataFrame.at ` .
236
237
237
238
Select via the position of the passed integers:
238
239
@@ -361,19 +362,19 @@ returns a copy of the data:
361
362
df1.loc[dates[0 ] : dates[1 ], " E" ] = 1
362
363
df1
363
364
364
- To drop any rows that have missing data:
365
+ :meth: ` DataFrame.dropna ` drops any rows that have missing data:
365
366
366
367
.. ipython :: python
367
368
368
369
df1.dropna(how = " any" )
369
370
370
- Filling missing data:
371
+ :meth: ` DataFrame.fillna ` fills missing data:
371
372
372
373
.. ipython :: python
373
374
374
375
df1.fillna(value = 5 )
375
376
376
- To get the boolean mask where values are ``nan ``:
377
+ :func: ` isna ` gets the boolean mask where values are ``nan ``:
377
378
378
379
.. ipython :: python
379
380
@@ -415,7 +416,7 @@ In addition, pandas automatically broadcasts along the specified dimension:
415
416
Apply
416
417
~~~~~
417
418
418
- Applying functions to the data:
419
+ :meth: ` DataFrame.apply ` applies a user defined function to the data:
419
420
420
421
.. ipython :: python
421
422
@@ -461,7 +462,7 @@ operations.
461
462
462
463
See the :ref: `Merging section <merging >`.
463
464
464
- Concatenating pandas objects together with :func: `concat `:
465
+ Concatenating pandas objects together along an axis with :func: `concat `:
465
466
466
467
.. ipython :: python
467
468
@@ -482,7 +483,7 @@ Concatenating pandas objects together with :func:`concat`:
482
483
Join
483
484
~~~~
484
485
485
- SQL style merges . See the :ref: `Database style joining <merging.join >` section.
486
+ :func: ` merge ` enables SQL style join types along specific columns . See the :ref: `Database style joining <merging.join >` section.
486
487
487
488
.. ipython :: python
488
489
@@ -572,7 +573,7 @@ columns:
572
573
stacked = df2.stack()
573
574
stacked
574
575
575
- With a "stacked" DataFrame or Series (having a `` MultiIndex ` ` as the
576
+ With a "stacked" DataFrame or Series (having a :class: ` MultiIndex ` as the
576
577
``index ``), the inverse operation of :meth: `~DataFrame.stack ` is
577
578
:meth: `~DataFrame.unstack `, which by default unstacks the **last level **:
578
579
@@ -599,7 +600,7 @@ See the section on :ref:`Pivot Tables <reshaping.pivot>`.
599
600
)
600
601
df
601
602
602
- We can produce pivot tables from this data very easily:
603
+ :func: ` pivot_table ` pivots a :class: ` DataFrame ` specifying the `` values ``, `` index `` and `` columns ``
603
604
604
605
.. ipython :: python
605
606
@@ -620,7 +621,7 @@ financial applications. See the :ref:`Time Series section <timeseries>`.
620
621
ts = pd.Series(np.random.randint(0 , 500 , len (rng)), index = rng)
621
622
ts.resample(" 5Min" ).sum()
622
623
623
- Time zone representation :
624
+ :meth: ` Series.tz_localize ` localizes a time series to a time zone :
624
625
625
626
.. ipython :: python
626
627
@@ -630,7 +631,7 @@ Time zone representation:
630
631
ts_utc = ts.tz_localize(" UTC" )
631
632
ts_utc
632
633
633
- Converting to another time zone:
634
+ :meth: ` Series.tz_convert ` converts a timezones aware time series to another time zone:
634
635
635
636
.. ipython :: python
636
637
@@ -722,7 +723,7 @@ We use the standard convention for referencing the matplotlib API:
722
723
723
724
plt.close(" all" )
724
725
725
- The :meth: ` ~ plt.close ` method is used to `close <https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.close.html >`__ a figure window:
726
+ The `` plt.close ` ` method is used to `close <https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.close.html >`__ a figure window:
726
727
727
728
.. ipython :: python
728
729
@@ -732,7 +733,7 @@ The :meth:`~plt.close` method is used to `close <https://matplotlib.org/3.1.1/ap
732
733
@savefig series_plot_basic.png
733
734
ts.plot();
734
735
735
- If running under Jupyter Notebook, the plot will appear on :meth: `~ts .plot `. Otherwise use
736
+ If running under Jupyter Notebook, the plot will appear on :meth: `~Series .plot `. Otherwise use
736
737
`matplotlib.pyplot.show <https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.show.html >`__ to show it or
737
738
`matplotlib.pyplot.savefig <https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html >`__ to write it to a file.
738
739
@@ -756,19 +757,19 @@ of the columns with labels:
756
757
@savefig frame_plot_basic.png
757
758
plt.legend(loc = ' best' );
758
759
759
- Getting data in/out
760
- -------------------
760
+ Importing and exporting data
761
+ ----------------------------
761
762
762
763
CSV
763
764
~~~
764
765
765
- :ref: `Writing to a csv file: <io.store_in_csv >`
766
+ :ref: `Writing to a csv file: <io.store_in_csv >` using :meth: ` DataFrame.to_csv `
766
767
767
768
.. ipython :: python
768
769
769
770
df.to_csv(" foo.csv" )
770
771
771
- :ref: `Reading from a csv file: <io.read_csv_table >`
772
+ :ref: `Reading from a csv file: <io.read_csv_table >` using :func: ` read_csv `
772
773
773
774
.. ipython :: python
774
775
@@ -786,13 +787,13 @@ HDF5
786
787
787
788
Reading and writing to :ref: `HDFStores <io.hdf5 >`.
788
789
789
- Writing to a HDF5 Store:
790
+ Writing to a HDF5 Store using :meth: ` DataFrame.to_hdf ` :
790
791
791
792
.. ipython :: python
792
793
793
794
df.to_hdf(" foo.h5" , " df" )
794
795
795
- Reading from a HDF5 Store:
796
+ Reading from a HDF5 Store using :func: ` read_hdf ` :
796
797
797
798
.. ipython :: python
798
799
@@ -806,15 +807,15 @@ Reading from a HDF5 Store:
806
807
Excel
807
808
~~~~~
808
809
809
- Reading and writing to :ref: `MS Excel <io.excel >`.
810
+ Reading and writing to :ref: `Excel <io.excel >`.
810
811
811
- Writing to an excel file:
812
+ Writing to an excel file using :meth: ` DataFrame.to_excel ` :
812
813
813
814
.. ipython :: python
814
815
815
816
df.to_excel(" foo.xlsx" , sheet_name = " Sheet1" )
816
817
817
- Reading from an excel file:
818
+ Reading from an excel file using :func: ` read_excel ` :
818
819
819
820
.. ipython :: python
820
821
@@ -828,16 +829,13 @@ Reading from an excel file:
828
829
Gotchas
829
830
-------
830
831
831
- If you are attempting to perform an operation you might see an exception like:
832
+ If you are attempting to perform a boolean operation on a :class: `Series ` or :class: `DataFrame `
833
+ you might see an exception like:
832
834
833
- .. code-block :: python
834
-
835
- >> > if pd.Series([False , True , False ]):
836
- ... print (" I was true" )
837
- Traceback
838
- ...
839
- ValueError : The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
835
+ .. ipython :: python
836
+ :okexcept:
840
837
841
- See :ref: `Comparisons<basics.compare> ` for an explanation and what to do.
838
+ if pd.Series([False , True , False ]):
839
+ print (" I was true" )
842
840
843
- See :ref: `Gotchas<gotchas> ` as well .
841
+ See :ref: `Comparisons<basics.compare> ` and :ref: ` Gotchas<gotchas> ` for an explanation and what to do .
0 commit comments