Python for Visualization Flashcards

1
Q

Pandas function that converts column to datetime type and return a series object

A

dataframe[‘col’] = pandas.to_datetime(df[‘col’])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Library used to create charts

A

matplotlib

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

matplotlib module that provides a high-level interface that allows us to quickly create common data plots and perform common tweaks to them

A

pyplot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Code to import pyplot module

A

import matplotlib.pyplot as plt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

pyplot functions to (1) create chart and (2) display

A

plt. plot(x_values, y_values, c=’color’, label=’label’)
plt. show()

For x and y values, matplotlib will accept any iterable object, like NumPy arrays and pandas.Series instances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

pyplot function to customize behavior of x-axis ticks

A

plt.xticks()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

pyplot function to modify x-axis labels

A

plt.xlabel()

accepts a string value, which gets set as the x-axis label

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

pyplot function to modify y-axis labels

A

plt.ylabel()

accepts a string value, which is set as the y-axis label

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

pyplot function to modify chart title

A

plt.title()

accepts a string value, which is set as the plot title

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

pyplot function to manually create a figure

A figure acts as a container for all plots and has methods for customizing the appearance and behavior for the plots within that container.

A

fig = plt.figure()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Method to add a subplot to an existing figure, which will return a new axes object that needs to be assigned to a variable

A

axes_obj = fig.add_subplot(nrows, ncols, plot_number)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Creating a figure with 2 plots, one above the other

A
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Parameter to adjust dimensions of the plotting area

A

figsize (use when calling plt.figure())

fig = plt.figure(figsize=(width, height))

Width & height are in inches

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Method to add a title to axes object

A

axes. set_title

ax1. set_title(‘Chart Name’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Built in type that represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops

A

range(start, stop[, step])

Ex: for i in range(5)
Produces a sequence of integers starting at zero, and going up to (but not including) the argument’s value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

pyplot function to create a legend

A

plt.legend(loc=’upper left’)

17
Q

Method to place a legend on the axes

A

axes.legend

18
Q

pyplot function to create a bar chart

A

plt.bar() or axes.bar(left=[position], height=[height], width=[width])

axes.bar allows easier customization
Ex: ax.bar(left=bar_positions, height=bar_heights, width=.5)

19
Q

Shortcut to generate a single subplot and return both the figure and axes object

A

fig, ax = plt.subplots()

20
Q

numpy function that returns evenly spaces values

A

np.arange([number of values to generate])

Ex:
from numpy import arange
bar_positions = arange(5) + .75

21
Q

Method to change positions of x ticks

A

axes.set_xticks()

Ex:
tick_positions = range(1,6)
ax.set_xticks(tick_positions)

22
Q

Method to specify tick labels

A

axes.set_xticklabels()

Ex:
num_cols = [list]
ax.set_xticklabels(num_cols)

23
Q

pyplot function to create a bar chart

A

axes.barh(bottom=[y coord], width=[length of bars])

24
Q

Methods to specify axes labels

A

axes. set_xlabel

axes. set_ylabel

25
Q

___ to generate scatter plot

A

axes.scatter(x=’x_values’, y=’y_values’)

26
Q

Sets data limits for axes

A

axes. setxlim(min, max)

axes. setylim(min, max)

27
Q

Method to generate a histogram

A

axes. hist()

ax. hist(df[‘col’], bins=10, range=(0, 5))

28
Q

Method to generate a boxplot

A

axes.boxplot()

ax. boxplot(norm_reviews[‘RT_user_norm’])
ax. set_xticklabels([“Rotten Tomatoes”])