Skip to content

Instantly share code, notes, and snippets.

@wyseow
Created Jan 3, 2020
Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pearson Correlation Coefficient: 0.5940885257860046 and a P-value of: 0.4059114742139954\n"
]
}
],
"source": [
"data = {'list 1':[1,2,3,2],'list 2':[2,5,5,1]}\n",
"\n",
"import pandas as pd #To Convert your lists to pandas data frames convert your lists into pandas dataframes\n",
"\n",
"df = pd.DataFrame(data, columns = ['list 1','list 2'])\n",
"\n",
"from scipy import stats # For in-built method to get PCC\n",
"\n",
"pearson_coef, p_value = stats.pearsonr(df[\"list 1\"], df[\"list 2\"]) #define the columns to perform calculations on\n",
"print(\"Pearson Correlation Coefficient: \", pearson_coef, \"and a P-value of:\", p_value) # Results "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.25"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(2+5+5+1)/4"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['hahaha ha']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'hahaha ha'.split('00')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment