Menu

1 / 2

Pandas' secret mini-language

DEV Community·Aaron Maxwell·6 months ago
#L8TYfIZz
Reading 0:00
15s threshold

The DataFrame class (from Pandas) is a work of art. Even if you never "do data", priceless lessons can be gleaned by studying this class.

It starts simple enough. Usually you will create a DataFrame by ingesting from a CSV file or database table or something. But you can whip up a small one like this:

import pandas as pd

df = pd . DataFrame ({ ' A ' : [ - 137 , 22 , - 3 , 4 , 5 ], ' B ' : [ 10 , 11 , 121 , 13 , 14 ], ' C ' : [ 3 , 6 , 91 , 12 , 15 ], })

Enter fullscreen mode

Exit fullscreen mode

This gives you a DataFrame with three columns, labeled A, B and C. With rows of data, like so:

>>> print(df) A B C 0 -137 10 3 1 22 11 6 2 -3 121 91 3 4 13 12 4 5 14 15

Enter fullscreen mode

Exit fullscreen mode

The first thing to notice is that DataFrame is a class. Once upon a time, there was no such thing as a DataFrame. Someone imagined it, and then coded it up.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.