Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
5
Indexable
Never
import pandas as pd
import os
import matplotlib.pyplot as plt
import scipy as scp
from scipy.stats import spearmanr
import seaborn as sns
import numpy as np
import matplotlib
matplotlib.rcParams['figure.figsize'] = [6, 6]
######
df = pd.read_csv('Austrian Survey on Privacy.csv')
df_KTP = df.iloc[:, [0,6,7,8,9,10] + list(range(145, 148)) + [169, 171, 177]]
df_PP = df.iloc[:, [0,6,7,8,9,10,300,306,314,315,316,317,318,319,326,327,328,329,330,331,332]]
df_KTP['knowledge_score'] = df_KTP.iloc[:,7:13].sum(axis=1, skipna=True)
df_PP['trust_score_authorities'] = df_PP.iloc[:,8:15].sum(axis=1, skipna=True)
df_PP['trust_score_big_tech'] = df_PP.iloc[:,15:20].sum(axis=1, skipna=True)
df_PP['trust_score_authorities'] = df_PP['trust_score_authorities'].divide(6, fill_value=np.nan)
df_PP['trust_score_big_tech'] = df_PP['trust_score_big_tech'].divide(5, fill_value=np.nan)
df_PP['trust_score'] = df_PP.iloc[:,[14,20,21,22]].sum(axis=1, skipna=True)
df_PP['trust_score'] = df_PP['trust_score'].replace(0, np.nan)
df_KTP['knowledge_score'] = df_KTP['knowledge_score'].replace(0, np.nan)
df_PP['trust_score_authorities'] = df_PP['trust_score_authorities'].replace(0, np.nan)
df_PP['trust_score_big_tech'] = df_PP['trust_score_big_tech'].replace(0, np.nan)
######
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('Younger than 18', 1)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('18-24', 1)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('25-34', 2)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('35-44', 3)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('45-54', 4)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('55-64', 5)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('65-74', 6)
df_PP['Please choose your age group'] = df_PP['Please choose your age group'].replace('Older than 75', 6)

df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('Younger than 18', 1)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('18-24', 1)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('25-34', 2)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('35-44', 3)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('45-54', 4)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('55-64', 5)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('65-74', 6)
df_KTP['Please choose your age group'] = df_KTP['Please choose your age group'].replace('Older than 75', 6)
######
sns.regplot(data=df_KTP, x='Please choose your age group', y='knowledge_score', line_kws={'color': 'red'})
sns.violinplot(data=df_KTP, y='How confident are you with using digital technologies?', x='Please choose your age group')
corr, pval = spearmanr(df_PP['Please choose your age group'], df_PP['trust_score'], nan_policy='omit')