To plot basic visualizations of data using pandas library in python.
Pandas series of data.
Bar chart, pie chart, scatter plot, histogram plot, etc.
df.plot.bar()
df.plot.pie()
df.plot.scatter()
df.plot.area()
df.plot.hist()
df.plot.barh()
Import pandas library.
Load the sample data.
Plot the variables, that you want to visualize.
#import libraries
import pandas as pd
import matplotlib.pyplot as plt
#load the sample data from iris.csv file
data = pd.read_csv(‘/home/soft50/soft50/Sathish/practice/iris.csv’)
#Make it as a data frame
df = pd.DataFrame(data)
#variable to plot
X = df[‘sepal_length’]
y = df[‘sepal_width’]
#plot Line Graph
X.plot()
plt.title(“Line Graph”)
plt.show()
print(“\n”)
#Bar chart
def Bar_chart(X):
X = X.sample(30)
X.plot.bar()
plt.title(“Bar chart”)
plt.show()
Bar_chart(X)
print(“\n”)
#Pie chart
def Pie_chart(X):
X = X.sample(30)
X.plot.pie()
plt.title(“Pie chart”)
plt.show()
Pie_chart(X)
print(“\n”)
#Area plot
a = df.iloc[:,0:5]
a.plot.area()
plt.title(“Area chart”)
plt.show()
print(“\n”)
#Histogram plot
a.plot.hist(bins=20)
plt.title(“Histogram”)
plt.show()
print(“\n”)
#Scatter plot
a.plot.scatter(x=’sepal_length’,y=’sepal_width’)
plt.title(“Scatter plot”)
plt.show()
print(“\n”)
#Stacked Bar chart
def Stacked_Bar_chart(X):
X = X.sample(15)
X.plot.barh(stacked=True)
plt.title(“Stacked Bar chart”)
plt.show()
Stacked_Bar_chart(a)
print(“\n”)