118 lines
3.0 KiB
Plaintext
118 lines
3.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" Bounce_Rate Visitors\n",
|
|
"Day \n",
|
|
"1 65 43\n",
|
|
"2 72 53\n",
|
|
"3 62 34\n",
|
|
"4 64 45\n",
|
|
"5 54 64\n",
|
|
"6 66 34\n",
|
|
"Day\n",
|
|
"1 43\n",
|
|
"2 53\n",
|
|
"3 34\n",
|
|
"4 45\n",
|
|
"5 64\n",
|
|
"6 34\n",
|
|
"Name: Visitors, dtype: int64\n",
|
|
" Bounce_Rate Visitors\n",
|
|
"Day \n",
|
|
"1 65 43\n",
|
|
"2 72 53\n",
|
|
"3 62 34\n",
|
|
"4 64 45\n",
|
|
"5 54 64\n",
|
|
"6 66 34\n",
|
|
"[43, 53, 34, 45, 64, 34]\n",
|
|
"[[65 43]\n",
|
|
" [72 53]\n",
|
|
" [62 34]\n",
|
|
" [64 45]\n",
|
|
" [54 64]\n",
|
|
" [66 34]]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"from matplotlib import style\n",
|
|
"style.use('ggplot')\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"web_stats={'Day':[1,2,3,4,5,6],\n",
|
|
" 'Visitors':[43,53,34,45,64,34],\n",
|
|
" 'Bounce_Rate':[65,72,62,64,54,66]}\n",
|
|
"\n",
|
|
"df=pd.DataFrame(web_stats)\n",
|
|
"\n",
|
|
"#print(df) #df stands for data frame\n",
|
|
"#print(df.head()) #prints the first 5 rows\n",
|
|
"#print(df.tail()) #prints the last 5 rows\n",
|
|
"#Specifying the number in the parentheses gives that number of rows\n",
|
|
"#print(df.head(2))\n",
|
|
"#print(df.tail(2))\n",
|
|
"\n",
|
|
"#df=df.set_index('Day')\n",
|
|
"\n",
|
|
"#OR you can do this:\n",
|
|
"df.set_index('Day', inplace=True)\n",
|
|
"print(df)\n",
|
|
"\n",
|
|
"#print (df['Visitors']) #prints specific column OR\n",
|
|
"print (df.Visitors)\n",
|
|
"\n",
|
|
"#referencing multiple columns\n",
|
|
"print (df[['Bounce_Rate','Visitors']])\n",
|
|
"\n",
|
|
"#making a list out of a column; this only work with one column because more than one would\n",
|
|
"#treat the dictionary like an array, which it isn't\n",
|
|
"print (df.Visitors.tolist())\n",
|
|
"\n",
|
|
"#to make it an array\n",
|
|
"print (np.array(df[['Bounce_Rate','Visitors']]))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"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.6.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|