In this article, we’ll talk about some libraries in Python, learn about API and then write a program to fetch data from API to make a fun interactive map plot.
Python is one of the easiest and most widely-used programming languages across the globe,
- Taught as a beginning programming language to students
- Clear syntax facilitates, ease of understanding and code indentation
- Active communities of libraries and modules developers
Pandas is a software library that is written for data manipulation and analysis, especially for Python. While Python supports lists and dictionaries for the manipulation of structured data, it is not well-suited for manipulating numerical tables, such as those stored in CSV files or JSON files.
Plotly Express is a wrapper for Plotly which enables developers to create, deploy and scale interactive visualizations.
Dataframe in Pandas are two-dimensional and heterogeneous tabular data that are mutable in size. Ie. Its size can be changed.
Application Programming Interface (API) is basically just an interface through which two systems — software applications or hardware-software intermediary can communicate to each other.
Anaconda is a distribution for scientific computing which is an easy-to-install free package manager and environment manager and has a collection of over 720 open-source packages offering free community support for R and Python programming languages. It supports Windows, Linux, and Mac OS and also ships with Jupyter Notebook.
Jupyter Notebook is an amalgamation of an IDE and also an educational tool for presentation which is used extensively and widely mostly for programming for scientific computing.
Here, we will try to make a small interesting fun program for beginner level to understand python, using some of the libraries for Python with an API. We’ll use the API to find the current location of the International Space Station and plot it in Map.
International Space Station is a station in Earth’s lower orbit that consists of modular components and is a collaboration between space agencies from different nations. The agencies include NAS, JAXA, ESA, CSA, and Roscosmos. International Space Station moves at around 28,000 km/h and thus the location changes continuously. We’ll try to locate it with this small program.
The simple API we’ll use returns the current location of the ISS. It returns the current latitude and longitude of the space station for the valid timestamp and takes no inputs.
Firstly, we import the libraries Pandas and Plotly express into our notebook.
import pandas as PDimport plotly.express as px
Use the API provided, which is scraped from the information published by NASA,
We set the URL link as a string to variable ‘URL’.
Changing order of Dataframe as per our need,
dataframe[‘latitude’] =dataframe.loc[‘latitude’,’iss_position’] dataframe[‘longitude’] =dataframe.loc[‘longitude’,’iss_position’] dataframe.reset_index(inplace=True)dataframe
Deleting the columns, we donot require,
dataframe=dataframe.drop([‘index’, ‘message’], axis =1)
What our final dataframe looks like before we plot our map,
Using Scatter Plot into the Geographical map,
figure =px.scatter_geo(dataframe, lat=’latitude’, lon=’longitude’)figure.show()
Hence, today we learned about Python and some of its libraries and API and used one in a real-world scenario to see how we can fetch data and use all of these components to make an application that can make an impact in real life. This was an article for beginners wanting to try a hands-on experience with components. The code can be accessed through this Github link.
Read Similar Articles from C# Corner: