Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Data Analysis using Python/Visualizations matplotlib pandas.ipynb
3074 views
Kernel: Python 3
import pandas as pd import seaborn as sns import numpy as np import matplotlib.pyplot as plt from matplotlib.pyplot import pie, axis, show %matplotlib inline import warnings # Ignore warning related to pandas_profiling warnings.filterwarnings('ignore')
viz_data=pd.read_excel("F:\ML & Data Visualization\EXAM PERFORMANCE.xlsx")
viz_data.head(2)
viz_data["age"].unique()
array([15, 16, 17], dtype=int64)
viz_data.count()
Gender 141 age 141 Class 141 math score 141 physics score 141 English 141 chemistry score 141 ROLL NO 141 dtype: int64
viz_data.describe()
pd.isnull('viz_data')
False
viz_data['physics score'].plot.hist(orientation='vertical', cumulative=True)
<matplotlib.axes._subplots.AxesSubplot at 0x247dccd8400>
Image in a Jupyter notebook
## Histogram viz_data.plot.hist(stacked=True, bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x247dcfef2b0>
Image in a Jupyter notebook
viz_data.plot.hist(stacked=False, bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x247dd18a160>
Image in a Jupyter notebook
viz_data.plot.hist(color='g', alpha=1, bins=50)##aplha for changing tranparency
<matplotlib.axes._subplots.AxesSubplot at 0x247dd293400>
Image in a Jupyter notebook
viz_data.plot.area()
<matplotlib.axes._subplots.AxesSubplot at 0x247de5a64e0>
Image in a Jupyter notebook
viz_data.plot(kind="bar",x='age',y='math score')
<matplotlib.axes._subplots.AxesSubplot at 0x247dd16ed68>
Image in a Jupyter notebook
viz_data.plot(kind="pie",x='age',y='physics score')
<matplotlib.axes._subplots.AxesSubplot at 0x247de9b14e0>
Image in a Jupyter notebook
viz_data['physics score'].plot.bar(orientation='horizontal')
<matplotlib.axes._subplots.AxesSubplot at 0x247dea05860>
Image in a Jupyter notebook
## boxplot = viz_data.boxplot(by='ROLL NO') boxplot = viz_data.boxplot(column = ['math score', 'physics score'], by=['age'])
Image in a Jupyter notebook
import matplotlib.pyplot as plt fig = plt.figure() fig.suptitle('Adding Subtitiles', fontsize=14, fontweight='bold') ax = fig.add_subplot(111) fig.subplots_adjust(top=0.85) ax.set_title('axes title') ax.set_xlabel('Label1') ax.set_ylabel('Label2') ax.text(3, 8, 'boxed italics text in data coords', style='italic', bbox={'facecolor':'Pink', 'alpha':0.5, 'pad':10}) ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) ax.text(3, 2, u'unicode: Institut f\374r Festk\366rperphysik') ax.text(0.95, 0.01, 'colored text in axes coords', verticalalignment='bottom', horizontalalignment='right', transform=ax.transAxes, color='green', fontsize=15) ax.plot([2], [1], 'o') ax.annotate('annotate', xy=(2, 1), xytext=(3, 4), arrowprops=dict(facecolor='black', shrink=0.05)) ax.axis([0, 10, 0, 10]) plt.show()
Image in a Jupyter notebook
rng = np.arange(50) rnd = np.random.randint(0, 10, size=(3, rng.size)) yrs = 1950 + rng fig, ax = plt.subplots(figsize=(5, 3)) ax.stackplot(yrs, rng + rnd, labels=['ROSA', 'EPIC', 'MEDAL']) ax.set_title('Combined debt growth over time') ax.legend(loc='upper left') ax.set_ylabel('Total debt') ax.set_xlim(xmin=yrs[0], xmax=yrs[-1]) fig.tight_layout()
Image in a Jupyter notebook
x = np.random.randint(low=1, high=11, size=50) y = x + np.random.randint(1, 5, size=x.size) data = np.column_stack((x, y)) fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 4)) ax1.scatter(x=x, y=y, marker='o', c='r', edgecolor='b') ax1.set_title('Scatter: $x$ versus $y$') ax1.set_xlabel('X-AXIS') ax1.set_ylabel('Y-AXIS') ax2.hist(data, bins=np.arange(data.min(), data.max()), label=('x', 'y')) ax2.legend(loc=(0.65, 0.8)) ax2.set_title('Frequencies of $x$ and $y$') ax2.yaxis.tick_right()
Image in a Jupyter notebook