Let`s use a real dataset from TRAI to analyze mobile data rates and try to see the average speeds for a particular operator or state this month. It will also show how easily Pandas can be used on any real data to produce interesting results.
About the dataset —
Telecommunications Regulatory Authority of India (TRAI ) releases a monthly dataset of internet speeds measured by it via the app MySpeed (TRAI) . This includes user-initiated speed tests or periodic background tests performed by the application. We will try to analyze this dataset and see the average speeds for a specific operator or state this month.
Checking the raw data structure:
1st column is of the Network Operator - JIO, Airtel etc.
2nd column is of the Network Technology strong> - 3G or 4G .
3rd column is the Type of Test initiated - upload or download .
4th column is the Speed Measured in Kilobytes per second.
5th column is the Signal Strength during the measurement.
6th column is the Local Service Area (LSA) , or the circle where the test was done - Delhi, Orissa etc. We will refer to this as simply `states`.
NOTE. Signal strength can be
na (Not Available) due to the fact that some devices cannot intercept the signal. We will ignore the use of this parameter in our calculations to simplify the process. However, this can easily be added as a condition when filtering.
Packages required -
Pandas - a popular data analysis toolkit. Very powerful for crunching large sets of data.
Numpy - provides fast and efficient operations on arrays of homogeneous data. We will use this to along with pandas and matplotlib.
Matplotlib - is a plotting library. We will use its bar plotting function to make bar graphs.
Let`s start analyzing the data.
Step # 1: strong> Import packages and define some constants.
Step # 2: Define multiple lists that will store the final computed results so they can be easily passed to function of building a histogram. The state (or operator), download speed, and download speed will be stored sequentially, so the index, state (or operator) and their corresponding download and upload speeds can be accessed.
final_states [2 ], final_download_speeds  and
final_upload_speeds  will give the corresponding values for the 3rd state.
Step # 3: Import the file using
read_csv () Pandas
read_csv () and save it to & # 39; df & # 39 ;. This will create a DataFrame of CSV content that we will work on.
Step # 4: First, let`s find all the unique states and statements in this dataset and store them in their respective lists of states and statements.
We will use
# find and display unique states
]. unique ()
` STATES Found: `
# find and display unique operators
]. unique ()
STATES Found: [`Kerala`` Rajasthan` `Maharashtra`` UP East`` Karnataka` nan `Madhya Pradesh`` Kolkata`` Bihar`` Gujarat`` UP West, Orissa, Tamil Nadu, Delhi, Assam, Andhra Pradesh, Haryana, Punjab, North East, Mumbai, Chennai, Himachal Pradesh, Jammu & amp; Kashmir`` West Bengal`] OPERATORS Found: [`IDEA`` JIO` `AIRTEL`` VODAFONE`` CELLONE`]
Step # 5: Define the
fixed_operator function, which will keep the statement constant and iterate over all the available states for that statement. We can build a similar function for a fixed state.
| tr> |
Kerala - Avg. Download: 26129.27 Avg. Upload: 5193.46 Rajasthan - Avg. Download: 27784.86 Avg. Upload: 5736.18 Maharashtra - Avg. Download: 20707.88 Avg. Upload: 4130.46 UP East - Avg. Download: 22451.35 Avg. Upload: 5727.95 Karnataka - Avg. Download: 16950.36 Avg. Upload: 4720.68 Madhya Pradesh - Avg. Download: 23594.85 Avg. Upload: 4802.89 Kolkata - Avg. Download: 26747.80 Avg. Upload: 5655.55 Bihar - Avg. Download: 31730.54 Avg. Upload: 6599.45 Gujarat - Avg. Download: 16377.43 Avg. Upload: 3642.89 UP West - Avg. Download: 23720.82 Avg. Upload: 5280.46 Orissa - Avg. Download: 31502.05 Avg. Upload: 6895.46 Tamil Nadu - Avg. Download: 16689.28 Avg. Upload: 4107.44 Delhi - Avg. Download: 20308.30 Avg. Upload: 4877.40 Assam - Avg. Download: 5653.49 Avg. Upload: 2864.47 Andhra Pradesh - Avg. Download: 32444.07 Avg. Upload: 5755.95 Haryana - Avg. Download: 7170.63 Avg. Upload: 2680.02 Punjab - Avg. Download: 14454.45 Avg. Upload: 4981.15 North East - Avg. Download: 6702.29 Avg. Upload: 2966.84 Mumbai - Avg. Download: 14070.97 Avg. Upload: 4118.21 Chennai - Avg. Download: 20054.47 Avg. Upload: 4602.35 Himachal Pradesh - Avg. Download: 7436.99 Avg. Upload: 4020.09 Jammu & amp; Kashmir - Avg. Download: 8759.20 Avg. Upload: 4418.21 West Bengal - Avg. Download: 16821.17 Avg. Upload: 3628.78
arange () method of Numpy, which returns evenly spaced values over a given interval. Here, passing the length of the list
final_states , we get values from 0 to the number of states in the list, for example [0, 1, 2, 3 ...]
Then we can use these indices to build a bar in this place. The second bar is constructed by offsetting the location of the first bar by the width of the bar.
Let`s also take data from another month and plot it together to see the difference in data rates.
We just need to follow the same steps again. Read the data for another month. Filter it on subsequent data frames and then plot it using a slightly different method. During the construction of the columns, we will grow the 3rd and 4th columns (corresponding to the upload and download of the second file) by 2 and 3 times the width of the columns so that they are in their correct positions.
Below is the implementation for comparison data for 2 months:
Books for developers
Programming with Python
Computer languages have so far been of the ‘interpreted’ or the ‘compiled’ type. Compiled languages (like ‘C’) have been more common. You prepare a program, save it (the debugged version),...
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python 3.6. Computing, in the sense of doing mathematical calculations, is a skill that mankind has developed over thousands of years. Programmin...
Machine Learning in Finance: From Theory to Practice
This book introduces machine learning methods in finance. It features a unified treatment of machine learn...
MySQL 8 for Big Data
Shabbir Challawala has over 8 years of rich experience in providing solutions based on MySQL and PHP technologies. He is currently working with KNOWARTH Technologies. He has worked in various PHP-base...
Submit new EBook