<jupyter_start><jupyter_text>Colouring dataframes & Anscombe's central tendancies<jupyter_code>import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
# https://matplotlib.org/2.0.2/index.html<jupyter_output><empty_output><jupyter_text>colouring dfs<jupyter_code># import cardiff weather

path = '/Users/aidanair/Documents/DATA/ALL_DATASETS/'
file = 'cardiff_weather.csv'

df = pd.read_csv(path + file)
# filter for last year

last = df[df.Year == 2019]
# sort by rainfall

last.sort_values(by = 'Rain (mm)')
# runa a bar chart in each column

last.sort_values(by = 'Rain (mm)', ascending = False).style.bar(color= 'lightblue')
# create a function to filter the numerical value into red color (ignoring strings an integers)

def color_below_20_red(value):
    
    if type(value) == type(''):
        return 'color:black'
    elif type(value) == int:
        return 'color:black'
    else:
        color = 'red' if value >= 80 else 'black'
        return 'color: {}'.format(color)

# apply function to any float cols (with data over 80)

last.style.applymap(color_below_20_red)
# colour on values along a scale min-max in each col

last.style.background_gradient(cmap = 'Blues')<jupyter_output><empty_output><jupyter_text>stats -- Anscombe (cf Interrogation)<jupyter_code>path = '/Users/aidanair/Documents/DATA/ALL_DATASETS/anscombe_csvs/'
files = ['ans1.csv', 'ans2.csv', 'ans3.csv', 'ans4.csv']

df1 = pd.read_csv(path + files[0])
df2 = pd.read_csv(path + files[1])
df3 = pd.read_csv(path + files[2])
df4 = pd.read_csv(path + files[3])
df1.describe()
df2.describe()
df3.describe()
df4.describe()
# plot scatterplot (in italics: force x axis to start at 0)
fig, ax = plt.subplots()
ax.scatter(df1.x1, df1.y1, color = 'r')
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)

# plot scatterplot (in italics: force x axis to start at 0)
fig, ax = plt.subplots()
ax.scatter(df2.x2, df2.y2, color = 'r')
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
# plot scatterplot (in italics: force x axis to start at 0)
fig, ax = plt.subplots()
ax.scatter(df3.x3, df3.y3, color = 'r')
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
# plot scatterplot (in italics: force x axis to start at 0)
fig, ax = plt.subplots()
ax.scatter(df4.x4, df4.y4, color = 'r')
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
path = '/Users/aidanair/Documents/DATA/ALL_DATASETS/'
file = 'figure_data.csv'

dfd = pd.read_csv(path + file)
dfd
# plot scatterplot (in italics: force x axis to start at 0)

fig, ax = plt.subplots()
ax.scatter(dfd.x, dfd.y, color = 'r')

ax.set_xlim(left=0)
ax.set_ylim(bottom=0)<jupyter_output><empty_output><jupyter_text>boxplot<jupyter_code>dfd.y.describe()
# look at column y in a box plot

plt.boxplot(dfd.y, showfliers=False, vert = False)
last['Rain (mm)'].median()
last.describe()
plt.boxplot(df['Rain (mm)'], showfliers=False, vert = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14699720670391062, 'fraction_numerical': 0.02164804469273743, 'mean_word_length': 4.943983402489627, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '445354', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1123, 'n_words': 268, 'path': 'wk_06_visualisation/notebook_data_files/viz 1 colouring Pandas & Anscombe.ipynb', 'repo_name': 'aodhanlutetiae/data_journalism_jomec', 'size': '2864'}