There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, and user input. Here is an example: "Use pip to install the packages in the requirements.txt file."
A block of code is set as follows. The start of the line will be preceded by >>> and continuations of that line will be preceded by ...:
>>> import pandas as pd
>>> df = pd.read_csv(
... 'data/fb_2018.csv', index_col='date', parse_dates=True
... )
>>> df.head()
Any code without the preceding >>> or ... is not something we will run—it is for reference:
try:
del df['ones']
except KeyError:
# handle the error here
pass
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
>>> df.plot(
... x='date',
... y='price',
... kind='line',
... title='Price over Time',
... legend=False,
... ylim=(0, None)
... )
Results will be shown without anything preceding the lines:
>>> pd.Series(np.random.rand(2), name='random')
0 0.235793
1 0.257935
Name: random, dtype: float64
Any command-line input or output is written as follows:
# Windows:
C:\path\of\your\choosing> mkdir pandas_exercises
# Linux, Mac, and shorthand:
$ mkdir pandas_exercises