Lectur2 PANDAS
Lectur2 PANDAS
A. Math
B. Pandas
C. Random
D. None of the above
Answer : B
Q. Important data structure of pandas is/are ___________
A. Series
B. Data Frame
C. Both of the above
D. None of the above
Answer : C
• Series can only contain single list with index, whereas dataframe can
be made of more than one series or we can say that a dataframe is a
collection of series that can be used to analyse the data.
Q. Which of the following object you get after reading CSV file?
A. DataFrame
B. Character Vector
C. Panel
D. All of the mentioned
Answer : A
Q. Which of the following library in Python is used for plotting
graphs and visualization.
A. Matplotlib
B. Pandas
C. NumPy
D. None of the above
Answer : A
Q. The most important object defined in NumPy is an N-dimensional
array type called?
A. ndarray
B. narray
C. nd_array
D. darray
Answer : A
Draw 2 plots
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(1, 2, 1)
plt.plot(x,y)
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.show()
Draw 2 plots on top of each other:
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(2, 1, 1)
plt.plot(x,y)
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(2, 1, 2)
plt.plot(x,y)
plt.show()
Bar chart in python
• A bar chart or bar graph is a chart or graph that presents categorical data
with rectangular bars with heights or lengths proportional to the values that
they represent. The bars can be plotted vertically or horizontally.
• A bar graph shows comparisons among discrete categories. One axis of the
chart shows the specific categories being compared, and the other axis
represents a measured value.
• Matplotlib API provides the bar() function that can be used in the MATLAB
style use as well as object oriented API. The signature of bar() function to be
used with axes object is as follows −
• ax.bar(x, height, width, bottom, align)The function makes a bar plot with the
bound rectangle of size (x −width = 2; x + width=2; bottom; bottom + height).
The parameters to the function are −
width scalar or array-like, optional. the width(s) of the bars default 0.8
bottom scalar or array-like, optional. the y coordinate(s) of the bars default None.
plt.pie(y)
plt.show()
• import matplotlib.pyplot as plt
import numpy as np
plt.hist(x)
plt.show()
from matplotlib import pyplot as plt
plt.hist(x, 10)
plt.show()