Path: blob/master/section-2-data-science-and-ml-tools/introduction-to-pandas-video.ipynb
874 views
Kernel: Python 3
In [1]:
In [2]:
In [3]:
Out[3]:
0 BMW
1 Toyota
2 Honda
dtype: object
In [4]:
In [5]:
Out[5]:
0 Red
1 Blue
2 White
dtype: object
In [6]:
Out[6]:
In [7]:
In [8]:
Out[8]:
In [11]:
In [12]:
Out[12]:
Describe data
In [13]:
Out[13]:
Make object
Colour object
Odometer (KM) int64
Doors int64
Price object
dtype: object
In [14]:
Out[14]:
Index(['Make', 'Colour', 'Odometer (KM)', 'Doors', 'Price'], dtype='object')
In [16]:
Out[16]:
Index(['Make', 'Colour', 'Odometer (KM)', 'Doors', 'Price'], dtype='object')
In [18]:
Out[18]:
RangeIndex(start=0, stop=10, step=1)
In [19]:
Out[19]:
In [20]:
Out[20]:
In [21]:
Out[21]:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 5 columns):
Make 10 non-null object
Colour 10 non-null object
Odometer (KM) 10 non-null int64
Doors 10 non-null int64
Price 10 non-null object
dtypes: int64(2), object(3)
memory usage: 528.0+ bytes
In [22]:
Out[22]:
Odometer (KM) 78601.4
Doors 4.0
dtype: float64
In [23]:
Out[23]:
38583.333333333336
In [24]:
Out[24]:
Make ToyotaHondaToyotaBMWNissanToyotaHondaHondaToyo...
Colour WhiteRedBlueBlackWhiteGreenBlueBlueWhiteWhite
Odometer (KM) 786014
Doors 40
Price $4,000.00$5,000.00$7,000.00$22,000.00$3,500.00...
dtype: object
In [25]:
Out[25]:
40
In [26]:
Out[26]:
10
In [27]:
Out[27]:
Viewing and selecting data
In [28]:
Out[28]:
In [29]:
Out[29]:
In [30]:
Out[30]:
In [32]:
Out[32]:
In [35]:
In [36]:
Out[36]:
0 cat
3 dog
9 bird
8 panda
3 snake
dtype: object
In [37]:
Out[37]:
3 dog
3 snake
dtype: object
In [38]:
Out[38]:
'bird'
In [40]:
Out[40]:
Make BMW
Colour Black
Odometer (KM) 11179
Doors 5
Price $22,000.00
Name: 3, dtype: object
In [42]:
Out[42]:
0 cat
3 dog
9 bird
8 panda
3 snake
dtype: object
In [41]:
Out[41]:
'panda'
In [43]:
Out[43]:
Make BMW
Colour Black
Odometer (KM) 11179
Doors 5
Price $22,000.00
Name: 3, dtype: object
In [44]:
Out[44]:
In [46]:
Out[46]:
0 cat
3 dog
9 bird
8 panda
3 snake
dtype: object
In [45]:
Out[45]:
0 cat
3 dog
9 bird
dtype: object
In [47]:
Out[47]:
In [48]:
Out[48]:
In [49]:
Out[49]:
0 Toyota
1 Honda
2 Toyota
3 BMW
4 Nissan
5 Toyota
6 Honda
7 Honda
8 Toyota
9 Nissan
Name: Make, dtype: object
In [50]:
Out[50]:
0 White
1 Red
2 Blue
3 Black
4 White
5 Green
6 Blue
7 Blue
8 White
9 White
Name: Colour, dtype: object
In [51]:
Out[51]:
0 Toyota
1 Honda
2 Toyota
3 BMW
4 Nissan
5 Toyota
6 Honda
7 Honda
8 Toyota
9 Nissan
Name: Make, dtype: object
In [54]:
Out[54]:
0 150043
1 87899
2 32549
3 11179
4 213095
5 99213
6 45698
7 54738
8 60000
9 31600
Name: Odometer (KM), dtype: int64
In [53]:
Out[53]:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-53-cffc0afb7077> in <module>
----> 1 car_sales.Odometer (KM)
~/Desktop/ml-course/sample-project/env/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
5177 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5178 return self[name]
-> 5179 return object.__getattribute__(self, name)
5180
5181 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'Odometer'
In [55]:
Out[55]:
In [56]:
Out[56]:
In [58]:
Out[58]:
In [57]:
Out[57]:
In [59]:
Out[59]:
In [61]:
In [60]:
Out[60]:
<matplotlib.axes._subplots.AxesSubplot at 0x123781ad0>
In [62]:
Out[62]:
<matplotlib.axes._subplots.AxesSubplot at 0x1234c6f10>
In [64]:
Out[64]:
dtype('O')
In [63]:
Out[63]:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-63-83bf2f29b5a6> in <module>
----> 1 car_sales["Price"].plot()
~/Desktop/ml-course/sample-project/env/lib/python3.7/site-packages/pandas/plotting/_core.py in __call__(self, *args, **kwargs)
792 data.columns = label_name
793
--> 794 return plot_backend.plot(data, kind=kind, **kwargs)
795
796 def line(self, x=None, y=None, **kwargs):
~/Desktop/ml-course/sample-project/env/lib/python3.7/site-packages/pandas/plotting/_matplotlib/__init__.py in plot(data, kind, **kwargs)
60 kwargs["ax"] = getattr(ax, "left_ax", ax)
61 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 62 plot_obj.generate()
63 plot_obj.draw()
64 return plot_obj.result
~/Desktop/ml-course/sample-project/env/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py in generate(self)
277 def generate(self):
278 self._args_adjust()
--> 279 self._compute_plot_data()
280 self._setup_subplots()
281 self._make_plot()
~/Desktop/ml-course/sample-project/env/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py in _compute_plot_data(self)
412 # no non-numeric frames or series allowed
413 if is_empty:
--> 414 raise TypeError("no numeric data to plot")
415
416 # GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
TypeError: no numeric data to plot
In [65]:
Out[65]:
In [ ]:
In [66]:
In [67]:
Out[67]:
In [68]:
Out[68]:
<matplotlib.axes._subplots.AxesSubplot at 0x1238437d0>
Manipulating Data
In [69]:
Out[69]:
0 toyota
1 honda
2 toyota
3 bmw
4 nissan
5 toyota
6 honda
7 honda
8 toyota
9 nissan
Name: Make, dtype: object
In [70]:
Out[70]:
In [71]:
In [72]:
Out[72]:
In [73]:
Out[73]:
In [74]:
Out[74]:
In [75]:
Out[75]:
92302.66666666667
In [76]:
Out[76]:
0 150043.000000
1 87899.000000
2 92302.666667
3 11179.000000
4 213095.000000
5 92302.666667
6 92302.666667
7 92302.666667
8 60000.000000
9 31600.000000
Name: Odometer, dtype: float64
In [78]:
Out[78]:
In [79]:
In [80]:
Out[80]:
In [81]:
Out[81]:
In [83]:
In [84]:
Out[84]:
In [89]:
Out[89]:
In [90]:
Out[90]:
In [91]:
In [92]:
Out[92]:
In [93]:
Out[93]:
In [94]:
In [96]:
Out[96]:
In [99]:
Out[99]:
In [102]:
In [103]:
Out[103]:
In [104]:
Out[104]:
In [106]:
Out[106]:
Make object
Colour object
Odometer (KM) int64
Doors int64
Price int64
Seats float64
Fuel per 100KM float64
Total fuel used float64
Total fuel used (L) float64
Number of wheels int64
Passed road saftey bool
dtype: object
In [107]:
Out[107]:
In [110]:
In [111]:
Out[111]:
In [125]:
In [126]:
Out[126]:
In [127]:
Out[127]:
In [128]:
Out[128]:
In [129]:
In [130]:
Out[130]:
In [131]:
Out[131]:
In [132]:
Out[132]:
In [ ]: