#-----------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------[ Needed Libraries Import ]----------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
import pandas as pd
import plotly.graph_objs as go
import numpy as np
import plotly.offline as py
import matplotlib.pyplot as plt
#-----------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------[ Import DataBase ]-------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
dataTelecom=pd.read_excel('S:\\TunisieTelecom\\TelecomData.xlsx')
dataTelecom.head(100)
STATUT | OFFRE | ANC_M | HANDSET | revenu_voix | revenu_inter | NB_JOUR_ACTIVITE_TAXE | NB_JOUR_APPEL_TAXE | DUREE_APPEL_TOT | DUREE_APPEL_TAXEE | ... | FREQ_USSD_VOIX | FREQ_USSD_SMS | VOLUME_SESSION | VOLUME_SESSION_WEEKEND | REVENU_VAS | ARPU | P_revenu_data | P_revenu_voix_c | P_revenu_vas_c | id_client | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Active | Offre30 | 123 | 2G | 12.709375 | 1.464447 | 10.366042 | 10.658842 | 27.261836 | 2.125971 | ... | 28.679570 | 146.930634 | 200000.000000 | 54.025577 | 1.059822 | 4.325398 | 0.136685 | 0.943095 | 0.279541 | 1.0 |
1 | Active | Offre8 | 98 | 2G | 3.000000 | 0.756078 | 1.330736 | 7.079320 | 19.883099 | 7.735475 | ... | 28.490597 | 169.219363 | 3337.992419 | 24.789260 | 1.411803 | 2.677563 | 0.533695 | 0.540374 | 0.712010 | 2.0 |
2 | Active | Offre24 | 90 | 4G | 32.514156 | 0.681197 | 0.158160 | 4.367702 | 133.476368 | 7.681088 | ... | 190.000000 | 44.403308 | 107082.775926 | 160.031496 | 18.195224 | 1.954007 | 0.799606 | 0.071368 | 0.376754 | 3.0 |
3 | Active | Offre10 | 226 | 2G | 3.821551 | 5.265345 | 4.003452 | 3.086766 | 35.053364 | 8.540951 | ... | 19.412661 | 190.000000 | 128700.752169 | 102.668979 | 17.746873 | 2.496790 | 0.426526 | 0.314082 | 0.676112 | 4.0 |
4 | Active | Offre1 | 139 | 2G | 60.009385 | 1.957144 | 5.689241 | 0.403300 | 0.844956 | 12.355853 | ... | 81.567146 | 6.365788 | 75654.384291 | 0.341570 | 7.280861 | 2.291381 | 0.319736 | 0.600057 | 0.719450 | 5.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
95 | Active | Offre8 | 159 | 2G | 3.000000 | 2.250293 | 21.961465 | 2.872333 | 1.826910 | 27.907662 | ... | 12.954468 | 23.226754 | 32664.259485 | 21.276030 | 6.134130 | 0.689345 | 0.857627 | 0.392768 | 0.657034 | 96.0 |
96 | Suspended | Offre2 | 145 | 2G | 3.000000 | 3.473084 | 3.575555 | 0.298674 | 80.858548 | 5.349497 | ... | 153.474792 | 190.000000 | 82909.748831 | 26.213769 | 1.504337 | 0.164892 | 0.980014 | 0.467268 | 0.150409 | 97.0 |
97 | Active | Offre10 | 185 | 2G | 4.531545 | 2.142349 | 3.470616 | 6.400014 | 107.330103 | 5.199869 | ... | 157.487581 | 36.176280 | 141996.977868 | 42.321968 | 1.637815 | 1.848815 | 0.772398 | 0.407095 | 0.545033 | 98.0 |
98 | Active | Offre15 | 197 | 3G | 11.762926 | 3.474145 | 2.842419 | 10.629819 | 86.011908 | 0.124836 | ... | 159.332900 | 77.858228 | 12052.670191 | 46.685004 | 1.422138 | 1.944146 | 0.152620 | 0.243845 | 0.387906 | 99.0 |
99 | Suspended | Offre30 | 178 | 2G | 17.606096 | 0.019640 | 1.850818 | 0.184009 | 89.864928 | 5.858613 | ... | 18.339092 | 47.120168 | 134081.459601 | 10.649038 | 0.640634 | 2.204618 | 0.893336 | 0.293854 | 0.121368 | 100.0 |
100 rows × 64 columns
#-----------------------------------------------------------------------------------------------------------------------------
#------------------------------------------------[ Interactive ScatterPlot]--------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
# Ask the user to enter the names of the x and y columns
x_col = input("Enter the name of the x column: ")
y_col = input("Enter the name of the y column: ")
# Ensure that the columns exist in the DataFrame
if x_col in dataTelecom.columns and y_col in dataTelecom.columns:
# Sort the data based on the y column (descending)
sorted_data = dataTelecom.sort_values(by=y_col, ascending=False)
# Create the scatter plot
plt.figure(figsize=(10, 6))
plt.scatter(sorted_data[x_col], sorted_data[y_col], alpha=0.5)
plt.title(f"Scatter Plot of {x_col} vs. {y_col}")
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.xticks(rotation=-90) # Rotate x-axis tick labels
plt.grid(True)
plt.show()
else:
print("The specified columns do not exist in the DataFrame.")
#-----------------------------------------------------------------------------------------------------------------------------
#------------------------------------------------[ Interactive Pie Plot ]-----------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
# Ask the user to enter the name of the column containing values
value_col = input("Write The Column Name You Wanna Visualize : ")
# Ensure that the column exists in the DataFrame
if value_col in dataTelecom.columns:
column_data = dataTelecom[value_col]
if pd.api.types.is_numeric_dtype(column_data):
max_value = column_data.max()
interval_width = max_value / 10 # Divide the range into 10 equal-width intervals
bins = [i * interval_width for i in range(12)]
labels = [f'{int(bins[i])}-{int(bins[i+1])}' for i in range(11)]
labels[-1] = f'{int(bins[-2])}+' # Replace last label with appropriate range
# Bin the numeric values into intervals
dataTelecom['interval'] = pd.cut(column_data, bins=bins, labels=labels, right=False)#->right=false:intervals are left-closed , right-open
# Count the occurrences of each interval
interval_counts = dataTelecom['interval'].value_counts()
else:
# For non-numeric values, keep them as they are
dataTelecom['interval'] = column_data
# Count the occurrences of each non-numeric value
interval_counts = dataTelecom['interval'].value_counts()
dist = interval_counts
colors = ['mediumturquoise', 'darkorange']
trace = go.Pie(values=np.array(dist), labels=dist.index)
layout = go.Layout(title=f"Disposition Of {x_col}S")
data = [trace]
fig = go.Figure(data, layout)
fig.update_traces(marker=dict(colors=colors, line=dict(color='#000000', width=1)))
py.iplot(fig)
else:
print("Column Name Incorrect")
#-----------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------[ Interactive Box - Plot ]--------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
# Ask the user to enter the name of the column containing numerical values
value_col = input("Enter the name of the column with numerical values: ")
# Ensure that the column exists in the DataFrame
if value_col in dataTelecom.columns:
# Create the box plot
plt.figure(figsize=(8, 6))
plt.boxplot(dataTelecom[value_col], vert=False)
plt.title(f"Box Plot of {value_col}")
plt.xlabel(value_col)
plt.show()
else:
print("The specified column does not exist in the DataFrame.")