import pandas as pd
from pandas_datareader import data
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
Electronic Production in India β Data Analysis and VisualizationΒΆ
This notebook analyzes electronic production data from India, demonstrating data transposition, export to Excel with pd.ExcelWriter, and visualization with both Plotly (interactive bar charts) and Matplotlib (line plots). The workflow includes setting a meaningful index with index_col, transposing DataFrames with .transpose() to reshape time-series data for plotting, and comparing static vs. interactive visualization libraries.
Why this matters: Government and industry production datasets often come in wide format (years as columns) that needs transposing for time-series analysis. This project shows how to reshape such data and produce both publication-quality static plots and interactive visualizations suitable for dashboards and presentations.
production = pd.read_csv("mobile_2.csv")
production_idx = pd.read_csv("mobile_2.csv", index_col="Item", parse_dates=True)
production_idx
production_t = production_idx.transpose()
production_t
path = r"mobile_t.xlsx"
writer = pd.ExcelWriter(path, engine = 'xlsxwriter')
production_t.to_excel(writer)
writer.save()
writer.close()
type(production_t)
import plotly
from plotly.graph_objs import Scatter, Layout
import plotly.graph_objs as go
literate = [go.Bar(x=production_t.index, y=production_t["Mobile Handsets"])]
plotly.offline.plot({ 'data': literate,
'layout': {
'title': 'POPULATION LITERACY RATE IN TN',
'xaxis': {
'title': 'YEAR'},
'yaxis': {
'title': 'POPULATION (in lakhs) '}
}})
plt.style.use("ggplot")
production.plot(x="Item")
production_idx.plot()