<jupyter_start><jupyter_text>Mean<jupyter_code>state_name = ['PA', 'OH', 'FL']
state_data = []
for x in state_name:
    data = df[df['state'] == x]['dem_share']
    state_data.append(data)
    
for i, x in enumerate(state_data):
    print("Rata rata dari %s adalah: %s" % (state_name[i], np.mean(x)))<jupyter_output>Rata rata dari PA adalah: 45.476417910447765
Rata rata dari OH adalah: 44.31818181818181
Rata rata dari FL adalah: 41.32507462686568<jupyter_text>$ mean = \bar{x} = \frac{1}{n}\sum_{n=i}^{n} x_i $<jupyter_code>np.mean(df['dem_share'])<jupyter_output><empty_output><jupyter_text>Outlier<jupyter_code>df_all = pd.read_csv('2008_all_states.csv')
df_all.head()
data_ut = df_all[df_all['state'] == 'UT']['dem_share']
sns.swarmplot(y=data_ut)
plt.xlabel('UT')
plt.ylabel('Suara untuk Obama')
np.mean(data_ut)
np.median(data_ut)
np.array(sorted(data_ut))
len(data_ut)<jupyter_output><empty_output><jupyter_text>Persentil dalam ECDF<jupyter_code>import dc_stat_think as dcst
x, y = dcst.ecdf(df['dem_share'])
plt.plot(x, y, marker='.', linestyle='none')
plt.xlabel('Presentase suara untuk Obama')
plt.ylabel('ECDF')
plt.margins(0.02) # Keeps data off plot edges
np.percentile(df['dem_share'], [25, 50, 75])<jupyter_output><empty_output><jupyter_text>Box Plot<jupyter_code>sns.boxplot(x='east_west', y='dem_share',
data=df_all)
plt.xlabel('Regional')
plt.ylabel('Presentase suara untuk Obama')<jupyter_output><empty_output><jupyter_text>Varians dan Standard Deviasi<jupyter_code>sns.swarmplot(x='state', y='dem_share', data=df)
plt.xlabel('State')
plt.ylabel('Presentasi suara untuk Obama')<jupyter_output><empty_output><jupyter_text>Varians- Jarark akar kuadarat dari meannya- Secara informal  merupakan ukuran dari sebaran data<jupyter_code>data_pa = df[df['state'] == 'PA']['dem_share']
data_oh = df[df['state'] == 'OH']['dem_share']
data_fl = df[df['state'] == 'FL']['dem_share']
sns.swarmplot(y=data_fl, color= sns.xkcd_rgb["pale red"])
plt.margins(0.3)
plt.xlabel('FL')
plt.ylabel('Presentasi suara untuk Obama')<jupyter_output><empty_output><jupyter_text>$ varians = \frac{1}{n}\sum_{n=i}^{n} (x_i - \bar{x})^2 $<jupyter_code>np.var(data_fl)
print(np.std(data_fl))
print(np.sqrt(np.var(data_fl)))<jupyter_output>12.142602117687158
12.1426021177<jupyter_text>Kovarians dan Korelasi Koefisien Pearson<jupyter_code>df_all.head()
plt.plot(df['total_votes']/1000, df['dem_share'], marker='.', linestyle='none')
plt.xlabel('total votes (thousands)')
plt.ylabel('percent of vote for Obama')
plt.scatter(df['total_votes']/1000, df['dem_share'])
plt.xlabel('Suara Total(Ribuan)')
plt.ylabel('Presentase Suara untuk Obama')<jupyter_output><empty_output><jupyter_text>Kovarians- Mengukur dua variabel bervariasi bersama<jupyter_code>np.cov(df['total_votes']/1000, df['dem_share'])[0,1]<jupyter_output><empty_output><jupyter_text>$ kovarians = \frac{1}{n}\sum_{n=i}^{n} (x_i - \bar{x})(y_i - \bar{y}) $  <NAME>  $ \rho = Pearson Correlation $  $ = \frac{Kovarians}{(std of x)(std of y)}$ $ = \frac{Variasidari kodepedensi}{Variabel Independen}$<jupyter_code>np.cov(df['total_votes']/1000, df['dem_share']) / (np.std(df['total_votes']/1000) * np.std(df['dem_share']))
np.corrcoef(df['total_votes']/1000, df['dem_share'])
from scipy.stats import pearsonr
pearsonr(df['total_votes']/1000, df['dem_share'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1847630473905219, 'fraction_numerical': 0.03809238152369526, 'mean_word_length': 8.808823529411764, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '378711', 'license': 'MIT', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1413, 'n_words': 203, 'path': 'Bagian 5 - Statistik dan Python 1/2. Summary Statistics.ipynb', 'repo_name': 'DimasWidyatama/Fundamental-Pandas', 'size': '3354'}