Python – Plotting DataFrame and Working with Pandas – Video

Working with Pandas is like working with Excel on steroids – it can really do a lot of things fast, but somehow doing the easy things get complicated. In this video and article tutorial I am presenting

  • loading data to a dataframe
  • how to select data from a dataframe in pandas
  • how to change and format the index of the dataframe
  • how to do a basic operations with pandas
  • plotting data in matplotlib
  • summing columns to a new column

To load data, which is used in the first part is taken from statsmodels datasets, we use the magic import statsmodels.api as sm. Once the data is loaded to a dataframe, it can be accessed through one the following:

To get the corresponding data:

Changing the index of the dataframe is quite an easy task. First, we need to produce a new index:

Once the index is produced, we may decide to format it. If we only need to get the year, this is the magic code to achieve so:

Selecting data from the dataframe is done with list comprehension. Plenty of ways to do so, however the easiest ones are these:

Basic operations with pandas are quite trivial – there are built-in functions like Sum(), ().Mean, etc ,which could be used for these:

Creating our own dataframe and plotting data with matplotlib is quite easy, with Jupyter notebook as well. We may generate a few lists and put them in the dataframe on a single loop:

Once this is carried out, the plotting of the data is a piece of cake:

Summing columns in python to a new column is not science fiction – the trick is to  remeber, that the axis of the column is always 1 (and the row is 0):

Pretty much that’s all. The Jupyter notebook is available in GitHub here:

Tagged with: , , , , , , ,