Insert Columns into a Pandas DataFrame
Let's find out how to add a column to a pandas DataFrame.
We'll cover the following...
We'll cover the following...
Try it yourself
Try executing the code below to see the result.
Explanation
Where did the late_fee column go?
Python’s objects are very dynamic. We can add attributes to most of them
as we please.
In [1]: class Point:
...: def __init__(self, x, y):
...: self.x, self.y = x, y
In [2]: p = Point(1, 2)
In [3]: p.x, p.y
Out[3]: (1, 2)
In [4]: p.z = 3
In [5]: p.z
Out[5]: ...