Examples¶
Following examples will walk you through how to use the PyForbes package.
PyForbes supports fetching data for 60+ Forbes Lists. You can find the supported ForbesList here: PyForbes Supported ForbesLists Index
Example 1: Get ForbesList data¶
The following example demonstrates how to get data for a specific Forbes List. We can get the data in three different data-types request.response, pandas.DataFrame and **dict**(JSON).
1from pyforbes import ForbesList
2
3 flist = ForbesList()
4 # Get Data as requests.response datatype
5 richest400_res = flist.get_response("forbes-400")
6
7 # Get Data as Pandas DataFrame
8 richest400_df = flist.get_df("forbes-400")
9
10 # Get Data as JSON Dict
11 richest400_json = flist.get_json("forbes-400")
Example 2: Get ForbesList data for a specific year¶
You can also fetch ForbesList data for a specific year. Similar to the previous example, we can get the data in three different data-types request.response, pandas.DataFrame and **dict**(JSON).
1from pyforbes import ForbesList
2
3 flist = ForbesList()
4 # Get Data as requests.response datatype for the year 2016
5 richest400_res = flist.get_response("forbes-400", year=2016)
6
7 # Get Data as Pandas DataFrame for the year 2017
8 richest400_df = flist.get_df("forbes-400", year=2017)
9
10 # Get Data as JSON Dict for the year 2018
11 richest400_json = flist.get_json("forbes-400", year=2018)