Data Visualization
General Info
Useful Snippets

13.0.2 Cool Charts

Example:

######################################################################################
# Cumulative Percent Column and Bar Chart
# Sort the data, create a 'cumulative_percent' on the sorted data, and create a 'rank' column for each columns

# 1. Sort the base column
DF_Sorted = DF.sort_values(['column_name'], ascending = False)

# 2. Create the cumulative % Column
DF_Sorted['cumulative_percent'] = 100*( DF_Sorted.column_name.cumsum() / DF_Sorted.column_name.sum() )

# 3. Create an index like column 'rank' to use as a label for the x-axis so that your chart looks pretty
DF_Sorted.insert(0, 'rank', range(1, 1+len(DF_Sorted['cumulative_percent'])))

# 4. Create a Bar Chart Showing the Cumulative percent
DF_Sorted.plot.bar(y = 'cumulative_percent', x = 'rank').set_ylabel("my_label_name")

######################################################################################
### Correlation Matrix
import seaborn as sn
import matplotlib.pyplot as plt

# Specify the columns to include in your correlation matrix
DF_base = DF[['column_name', 'column_two', 'column_three' ]]

# use .corr() to create a correlation matrix dataframe
DF_corr_matrix = DF_base.corr()

# Plot the correlation matrix
plt.figure(figsize = (3,3))
sn.heatmap(DF_corr_matrix, annot=True)
plt.show()