pandas Meta: Documentation Guidelines Showing code snippets and output

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Two popular options are to use:

ipython notation:

In [11]: df = pd.DataFrame([[1, 2], [3, 4]])

In [12]: df
Out[12]:
   0  1
0  1  2
1  3  4

Alternatively (this is popular over in the python documentation) and more concisely:

df.columns  # Out: RangeIndex(start=0, stop=2, step=1)

df[0]
# Out:
# 0    1
# 1    3
# Name: 0, dtype: int64

for col in df:
    print(col)
# prints:
# 0
# 1

Generally, this is better for smaller examples.

Note: The distinction between output and printing. ipython makes this clear (the prints occur before the output is returned):

In [21]: [print(col) for col in df]
0
1
Out[21]: [None, None]


Got any pandas Question?