Preface |
|
xiii | |
Acknowledgments |
|
xv | |
About This Book |
|
xvii | |
About The Author |
|
xx | |
About The Cover Illustration |
|
xxi | |
Part 1 Core Pandas |
|
|
|
3 | (19) |
|
1.1 Data in the 21st century |
|
|
4 | (1) |
|
|
4 | (5) |
|
Pandas vs. graphical spreadsheet applications |
|
|
6 | (2) |
|
Pandas vs. its competitors |
|
|
8 | (1) |
|
|
9 | (13) |
|
|
9 | (2) |
|
|
11 | (3) |
|
Counting values in a Series |
|
|
14 | (1) |
|
Filtering a column by one or more criteria |
|
|
15 | (3) |
|
|
18 | (4) |
|
|
22 | (32) |
|
|
23 | (7) |
|
|
24 | (1) |
|
Populating the Series with values |
|
|
24 | (2) |
|
Customizing the Series index |
|
|
26 | (3) |
|
Creating a Series with missing values |
|
|
29 | (1) |
|
2.2 Creating a Series from Python objects |
|
|
30 | (2) |
|
|
32 | (2) |
|
2.4 Retrieving the first and last rows |
|
|
34 | (2) |
|
2.5 Mathematical operations |
|
|
36 | (12) |
|
|
36 | (7) |
|
|
43 | (2) |
|
|
45 | (3) |
|
2.6 Passing the Series to Python's built-in functions |
|
|
48 | (2) |
|
|
50 | (1) |
|
|
50 | (1) |
|
|
50 | (4) |
|
|
54 | (25) |
|
3.1 Importing a data set with the read_csv function |
|
|
55 | (5) |
|
|
60 | (5) |
|
Sorting by values with the sort values method |
|
|
60 | (2) |
|
Sorting by index with the sort index method |
|
|
62 | (2) |
|
Retrieving the smallest and largest values with the nsmallest and nlargest methods |
|
|
64 | (1) |
|
3.3 Overwriting a Series with the inplace parameter |
|
|
65 | (1) |
|
3.4 Counting values with the value_counts method |
|
|
66 | (6) |
|
3.5 Invoking a function on every Series value with the apply method |
|
|
72 | (3) |
|
|
75 | (1) |
|
|
75 | (1) |
|
|
76 | (3) |
|
|
79 | (34) |
|
4.1 Overview of a DataFrame |
|
|
80 | (3) |
|
Creating a DataFrame from a dictionary |
|
|
80 | (1) |
|
Creating a DataFrame from a NumPy ndarray |
|
|
81 | (2) |
|
4.2 Similarities between Series and DataFrames |
|
|
83 | (7) |
|
Importing a DataFrame with the read_csv function |
|
|
83 | (1) |
|
Shared and exclusive attributes of Series and DataFrames |
|
|
84 | (3) |
|
Shared methods of Series and DataFrames |
|
|
87 | (3) |
|
|
90 | (4) |
|
Sorting by a single column |
|
|
90 | (2) |
|
Sorting by multiple columns |
|
|
92 | (2) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
95 | (1) |
|
4.6 Selecting columns and rows from a DataFrame |
|
|
96 | (3) |
|
Selecting a single column from a DataFrame |
|
|
96 | (1) |
|
Selecting multiple columns from a DataFrame |
|
|
97 | (2) |
|
4.7 Selecting rows from a DataFrame |
|
|
99 | (7) |
|
Extracting rows by index label |
|
|
99 | (2) |
|
Extracting rows by index position |
|
|
101 | (2) |
|
Extracting values from specific columns |
|
|
103 | (3) |
|
4.8 Extracting values from Series |
|
|
106 | (1) |
|
4.9 Renaming columns or rows |
|
|
106 | (2) |
|
|
108 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
109 | (4) |
|
|
113 | (32) |
|
5.1 Optimizing a data set for memory use |
|
|
114 | (6) |
|
Converting data types with the astype method |
|
|
116 | (4) |
|
5.2 Filtering by a single condition |
|
|
120 | (4) |
|
5.3 Filtering by multiple conditions |
|
|
124 | (3) |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
5.4 Filtering by condition |
|
|
127 | (7) |
|
|
127 | (1) |
|
|
128 | (2) |
|
The isnull and notnull methods |
|
|
130 | (2) |
|
|
132 | (2) |
|
5.5 Dealing with duplicates |
|
|
134 | (5) |
|
|
134 | (2) |
|
The drop_duplicates method |
|
|
136 | (3) |
|
|
139 | (1) |
|
|
139 | (1) |
|
|
140 | (5) |
Part 2 Applied Pandas |
|
145 | (184) |
|
|
147 | (18) |
|
6.1 Letter casing and whitespace |
|
|
148 | (3) |
|
|
151 | (2) |
|
6.3 String slicing and character replacement |
|
|
153 | (2) |
|
|
155 | (2) |
|
|
157 | (5) |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
162 | (1) |
|
6.7 A note on regular expressions |
|
|
163 | (2) |
|
|
165 | (33) |
|
7.1 The MultiIndex object |
|
|
166 | (4) |
|
7.2 MultiIndex DataFrames |
|
|
170 | (5) |
|
|
175 | (4) |
|
7.4 Selecting with a MultiIndex |
|
|
179 | (9) |
|
Extracting one or more columns |
|
|
179 | (3) |
|
Extracting one or more rows with loc |
|
|
182 | (4) |
|
Extracting one or more rows with iloc |
|
|
186 | (2) |
|
|
188 | (1) |
|
7.6 Manipulating the Index |
|
|
189 | (5) |
|
|
189 | (4) |
|
|
193 | (1) |
|
|
194 | (1) |
|
|
194 | (1) |
|
|
195 | (3) |
|
|
198 | (22) |
|
|
199 | (1) |
|
8.2 Creating a pivot table from a DataFrame |
|
|
200 | (7) |
|
|
201 | (4) |
|
Additional options for pivot tables |
|
|
205 | (2) |
|
8.3 Stacking and unstacking index levels |
|
|
207 | (2) |
|
|
209 | (4) |
|
8.5 Exploding a list of values |
|
|
213 | (1) |
|
|
214 | (1) |
|
|
214 | (1) |
|
|
215 | (5) |
|
|
220 | (19) |
|
9.1 Creating a GroupBy object from scratch |
|
|
221 | (1) |
|
9.2 Creating a GroupBy object from a data set |
|
|
222 | (3) |
|
9.3 Attributes and methods of a GroupBy object |
|
|
225 | (4) |
|
|
229 | (3) |
|
9.5 Applying a custom operation to all groups |
|
|
232 | (1) |
|
9.6 Grouping by multiple columns |
|
|
233 | (2) |
|
|
235 | (1) |
|
|
235 | (1) |
|
|
235 | (4) |
|
10 Merging, joining, and concatenating |
|
|
239 | (21) |
|
10.1 Introducing the data sets |
|
|
241 | (2) |
|
10.2 Concatenating data sets |
|
|
243 | (2) |
|
10.3 Missing values in concatenated DataFrames |
|
|
245 | (2) |
|
|
247 | (2) |
|
|
249 | (2) |
|
|
251 | (2) |
|
10.7 Merging on index labels |
|
|
253 | (1) |
|
|
254 | (2) |
|
|
256 | (1) |
|
|
256 | (4) |
|
11 Working with dates and times |
|
|
260 | (29) |
|
11.1 Introducing the Timestamp object |
|
|
261 | (5) |
|
How Python works with datetimes |
|
|
261 | (3) |
|
How pandas works with datetimes |
|
|
264 | (2) |
|
11.2 Storing multiple timestamps in a DatetimeIndex |
|
|
266 | (2) |
|
11.3 Converting column or index values to datetimes |
|
|
268 | (1) |
|
11.4 Using the DatetimeProperties object |
|
|
269 | (4) |
|
11.5 Adding and subtracting durations of time |
|
|
273 | (2) |
|
|
275 | (2) |
|
11.7 The Timedelta object |
|
|
277 | (5) |
|
|
282 | (1) |
|
|
282 | (1) |
|
|
283 | (6) |
|
|
289 | (21) |
|
12.1 Reading from and writing to JSON files |
|
|
290 | (9) |
|
Loading a ISON file Into a DataFrame |
|
|
292 | (6) |
|
Exporting a DataFrame to a JSON file |
|
|
298 | (1) |
|
12.2 Reading from and writing to CSV files |
|
|
299 | (2) |
|
12.3 Reading from and writing to Excel workbooks |
|
|
301 | (5) |
|
Installing the xlrd and openpyxl libraries in an Anaconda environment |
|
|
301 | (1) |
|
Importing Excel workbooks |
|
|
302 | (3) |
|
Exporting Excel workbooks |
|
|
305 | (1) |
|
|
306 | (1) |
|
|
307 | (1) |
|
|
307 | (3) |
|
|
310 | (9) |
|
13.1 Getting and setting pandas options |
|
|
311 | (4) |
|
|
315 | (1) |
|
13.3 Maximum column width |
|
|
316 | (1) |
|
|
316 | (1) |
|
|
317 | (2) |
|
|
319 | (10) |
|
14.1 Installing matplotlib |
|
|
320 | (1) |
|
|
320 | (5) |
|
|
325 | (2) |
|
|
327 | (2) |
Appendix A Installation and setup |
|
329 | (18) |
Appendix B Python crash course |
|
347 | (36) |
Appendix C NumPy crash course |
|
383 | (8) |
Appendix D Generating fake data with Faker |
|
391 | (6) |
Appendix E Regular expressions |
|
397 | (12) |
Index |
|
409 | |