Created
January 18, 2019 22:07
-
-
Save GuillaumeRouja/11531057199a679b3cc483cd32aabab9 to your computer and use it in GitHub Desktop.
Panda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat_minor": 1, | |
"cells": [ | |
{ | |
"execution_count": 1, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": "Requirement not upgraded as not directly required: xlrd in /opt/conda/envs/DSX-Python35/lib/python3.5/site-packages\r\n" | |
} | |
], | |
"source": "# Dependency needed to install file \n\n!pip install xlrd" | |
}, | |
{ | |
"execution_count": 2, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [], | |
"source": "# Import required library\n\nimport pandas as pd" | |
}, | |
{ | |
"execution_count": 3, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [], | |
"source": "# Read data from CSV file\n\ncsv_path = 'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%204/Datasets/TopSellingAlbums.csv'\ndf = pd.read_csv(csv_path)" | |
}, | |
{ | |
"execution_count": 4, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 4, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Artist</th>\n <th>Album</th>\n <th>Released</th>\n <th>Length</th>\n <th>Genre</th>\n <th>Music Recording Sales (millions)</th>\n <th>Claimed Sales (millions)</th>\n <th>Released.1</th>\n <th>Soundtrack</th>\n <th>Rating</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Michael Jackson</td>\n <td>Thriller</td>\n <td>1982</td>\n <td>0:42:19</td>\n <td>pop, rock, R&B</td>\n <td>46.0</td>\n <td>65</td>\n <td>30-Nov-82</td>\n <td>NaN</td>\n <td>10.0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>AC/DC</td>\n <td>Back in Black</td>\n <td>1980</td>\n <td>0:42:11</td>\n <td>hard rock</td>\n <td>26.1</td>\n <td>50</td>\n <td>25-Jul-80</td>\n <td>NaN</td>\n <td>9.5</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Pink Floyd</td>\n <td>The Dark Side of the Moon</td>\n <td>1973</td>\n <td>0:42:49</td>\n <td>progressive rock</td>\n <td>24.2</td>\n <td>45</td>\n <td>01-Mar-73</td>\n <td>NaN</td>\n <td>9.0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Whitney Houston</td>\n <td>The Bodyguard</td>\n <td>1992</td>\n <td>0:57:44</td>\n <td>R&B, soul, pop</td>\n <td>27.4</td>\n <td>44</td>\n <td>17-Nov-92</td>\n <td>Y</td>\n <td>8.5</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Meat Loaf</td>\n <td>Bat Out of Hell</td>\n <td>1977</td>\n <td>0:46:33</td>\n <td>hard rock, progressive rock</td>\n <td>20.6</td>\n <td>43</td>\n <td>21-Oct-77</td>\n <td>NaN</td>\n <td>8.0</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Artist Album Released Length \\\n0 Michael Jackson Thriller 1982 0:42:19 \n1 AC/DC Back in Black 1980 0:42:11 \n2 Pink Floyd The Dark Side of the Moon 1973 0:42:49 \n3 Whitney Houston The Bodyguard 1992 0:57:44 \n4 Meat Loaf Bat Out of Hell 1977 0:46:33 \n\n Genre Music Recording Sales (millions) \\\n0 pop, rock, R&B 46.0 \n1 hard rock 26.1 \n2 progressive rock 24.2 \n3 R&B, soul, pop 27.4 \n4 hard rock, progressive rock 20.6 \n\n Claimed Sales (millions) Released.1 Soundtrack Rating \n0 65 30-Nov-82 NaN 10.0 \n1 50 25-Jul-80 NaN 9.5 \n2 45 01-Mar-73 NaN 9.0 \n3 44 17-Nov-92 Y 8.5 \n4 43 21-Oct-77 NaN 8.0 " | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Print first five rows of the dataframe\n\ndf.head()" | |
}, | |
{ | |
"execution_count": 5, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 5, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Artist</th>\n <th>Album</th>\n <th>Released</th>\n <th>Length</th>\n <th>Genre</th>\n <th>Music Recording Sales (millions)</th>\n <th>Claimed Sales (millions)</th>\n <th>Released.1</th>\n <th>Soundtrack</th>\n <th>Rating</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Michael Jackson</td>\n <td>Thriller</td>\n <td>1982</td>\n <td>00:42:19</td>\n <td>pop, rock, R&B</td>\n <td>46.0</td>\n <td>65</td>\n <td>1982-11-30</td>\n <td>NaN</td>\n <td>10.0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>AC/DC</td>\n <td>Back in Black</td>\n <td>1980</td>\n <td>00:42:11</td>\n <td>hard rock</td>\n <td>26.1</td>\n <td>50</td>\n <td>1980-07-25</td>\n <td>NaN</td>\n <td>9.5</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Pink Floyd</td>\n <td>The Dark Side of the Moon</td>\n <td>1973</td>\n <td>00:42:49</td>\n <td>progressive rock</td>\n <td>24.2</td>\n <td>45</td>\n <td>1973-03-01</td>\n <td>NaN</td>\n <td>9.0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Whitney Houston</td>\n <td>The Bodyguard</td>\n <td>1992</td>\n <td>00:57:44</td>\n <td>R&B, soul, pop</td>\n <td>27.4</td>\n <td>44</td>\n <td>1992-11-17</td>\n <td>Y</td>\n <td>8.5</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Meat Loaf</td>\n <td>Bat Out of Hell</td>\n <td>1977</td>\n <td>00:46:33</td>\n <td>hard rock, progressive rock</td>\n <td>20.6</td>\n <td>43</td>\n <td>1977-10-21</td>\n <td>NaN</td>\n <td>8.0</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Artist Album Released Length \\\n0 Michael Jackson Thriller 1982 00:42:19 \n1 AC/DC Back in Black 1980 00:42:11 \n2 Pink Floyd The Dark Side of the Moon 1973 00:42:49 \n3 Whitney Houston The Bodyguard 1992 00:57:44 \n4 Meat Loaf Bat Out of Hell 1977 00:46:33 \n\n Genre Music Recording Sales (millions) \\\n0 pop, rock, R&B 46.0 \n1 hard rock 26.1 \n2 progressive rock 24.2 \n3 R&B, soul, pop 27.4 \n4 hard rock, progressive rock 20.6 \n\n Claimed Sales (millions) Released.1 Soundtrack Rating \n0 65 1982-11-30 NaN 10.0 \n1 50 1980-07-25 NaN 9.5 \n2 45 1973-03-01 NaN 9.0 \n3 44 1992-11-17 Y 8.5 \n4 43 1977-10-21 NaN 8.0 " | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Read data from Excel File and print the first five rows\n\nxlsx_path = 'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%204/Datasets/TopSellingAlbums.xlsx'\n\ndf = pd.read_excel(xlsx_path)\ndf.head()" | |
}, | |
{ | |
"execution_count": 6, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 6, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Length</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>00:42:19</td>\n </tr>\n <tr>\n <th>1</th>\n <td>00:42:11</td>\n </tr>\n <tr>\n <th>2</th>\n <td>00:42:49</td>\n </tr>\n <tr>\n <th>3</th>\n <td>00:57:44</td>\n </tr>\n <tr>\n <th>4</th>\n <td>00:46:33</td>\n </tr>\n <tr>\n <th>5</th>\n <td>00:43:08</td>\n </tr>\n <tr>\n <th>6</th>\n <td>01:15:54</td>\n </tr>\n <tr>\n <th>7</th>\n <td>00:40:01</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Length\n0 00:42:19\n1 00:42:11\n2 00:42:49\n3 00:57:44\n4 00:46:33\n5 00:43:08\n6 01:15:54\n7 00:40:01" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Access to the column Length\n\nx = df[['Length']]\nx" | |
}, | |
{ | |
"execution_count": 7, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 7, | |
"metadata": {}, | |
"data": { | |
"text/plain": "0 00:42:19\n1 00:42:11\n2 00:42:49\n3 00:57:44\n4 00:46:33\n5 00:43:08\n6 01:15:54\n7 00:40:01\nName: Length, dtype: object" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Get the column as a series\n\nx = df['Length']\nx" | |
}, | |
{ | |
"execution_count": 9, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 9, | |
"metadata": {}, | |
"data": { | |
"text/plain": "pandas.core.frame.DataFrame" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Get the column as a dataframe\n\nx = type(df[['Artist']])\nx" | |
}, | |
{ | |
"execution_count": 10, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 10, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Artist</th>\n <th>Length</th>\n <th>Genre</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Michael Jackson</td>\n <td>00:42:19</td>\n <td>pop, rock, R&B</td>\n </tr>\n <tr>\n <th>1</th>\n <td>AC/DC</td>\n <td>00:42:11</td>\n <td>hard rock</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Pink Floyd</td>\n <td>00:42:49</td>\n <td>progressive rock</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Whitney Houston</td>\n <td>00:57:44</td>\n <td>R&B, soul, pop</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Meat Loaf</td>\n <td>00:46:33</td>\n <td>hard rock, progressive rock</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Eagles</td>\n <td>00:43:08</td>\n <td>rock, soft rock, folk rock</td>\n </tr>\n <tr>\n <th>6</th>\n <td>Bee Gees</td>\n <td>01:15:54</td>\n <td>disco</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Fleetwood Mac</td>\n <td>00:40:01</td>\n <td>soft rock</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Artist Length Genre\n0 Michael Jackson 00:42:19 pop, rock, R&B\n1 AC/DC 00:42:11 hard rock\n2 Pink Floyd 00:42:49 progressive rock\n3 Whitney Houston 00:57:44 R&B, soul, pop\n4 Meat Loaf 00:46:33 hard rock, progressive rock\n5 Eagles 00:43:08 rock, soft rock, folk rock\n6 Bee Gees 01:15:54 disco\n7 Fleetwood Mac 00:40:01 soft rock" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Access to multiple columns\n\ny = df[['Artist','Length','Genre']]\ny" | |
}, | |
{ | |
"execution_count": 12, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 12, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Album</th>\n <th>Released</th>\n <th>Length</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Thriller</td>\n <td>1982</td>\n <td>00:42:19</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Back in Black</td>\n <td>1980</td>\n <td>00:42:11</td>\n </tr>\n <tr>\n <th>2</th>\n <td>The Dark Side of the Moon</td>\n <td>1973</td>\n <td>00:42:49</td>\n </tr>\n <tr>\n <th>3</th>\n <td>The Bodyguard</td>\n <td>1992</td>\n <td>00:57:44</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Bat Out of Hell</td>\n <td>1977</td>\n <td>00:46:33</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Their Greatest Hits (1971-1975)</td>\n <td>1976</td>\n <td>00:43:08</td>\n </tr>\n <tr>\n <th>6</th>\n <td>Saturday Night Fever</td>\n <td>1977</td>\n <td>01:15:54</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Rumours</td>\n <td>1977</td>\n <td>00:40:01</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Album Released Length\n0 Thriller 1982 00:42:19\n1 Back in Black 1980 00:42:11\n2 The Dark Side of the Moon 1973 00:42:49\n3 The Bodyguard 1992 00:57:44\n4 Bat Out of Hell 1977 00:46:33\n5 Their Greatest Hits (1971-1975) 1976 00:43:08\n6 Saturday Night Fever 1977 01:15:54\n7 Rumours 1977 00:40:01" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "z= df[['Album','Released','Length']]\nz" | |
}, | |
{ | |
"execution_count": 13, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 13, | |
"metadata": {}, | |
"data": { | |
"text/plain": "'Michael Jackson'" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Access the value on the first row and the first column\n\ndf.iloc[0, 0]" | |
}, | |
{ | |
"execution_count": 14, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 14, | |
"metadata": {}, | |
"data": { | |
"text/plain": "'AC/DC'" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Access the value on the second row and the first column\n\ndf.iloc[1,0]" | |
}, | |
{ | |
"execution_count": 15, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 15, | |
"metadata": {}, | |
"data": { | |
"text/plain": "'Michael Jackson'" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Access the column using the name\n\ndf.loc[0, 'Artist']" | |
}, | |
{ | |
"execution_count": 16, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 16, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Artist</th>\n <th>Album</th>\n <th>Released</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Michael Jackson</td>\n <td>Thriller</td>\n <td>1982</td>\n </tr>\n <tr>\n <th>1</th>\n <td>AC/DC</td>\n <td>Back in Black</td>\n <td>1980</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Artist Album Released\n0 Michael Jackson Thriller 1982\n1 AC/DC Back in Black 1980" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Slicing the dataframe\n\ndf.iloc[0:2, 0:3]" | |
}, | |
{ | |
"execution_count": 17, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 17, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Artist</th>\n <th>Album</th>\n <th>Released</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Michael Jackson</td>\n <td>Thriller</td>\n <td>1982</td>\n </tr>\n <tr>\n <th>1</th>\n <td>AC/DC</td>\n <td>Back in Black</td>\n <td>1980</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Pink Floyd</td>\n <td>The Dark Side of the Moon</td>\n <td>1973</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Artist Album Released\n0 Michael Jackson Thriller 1982\n1 AC/DC Back in Black 1980\n2 Pink Floyd The Dark Side of the Moon 1973" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "# Slicing the dataframe using name\n\ndf.loc[0:2, 'Artist':'Released']" | |
}, | |
{ | |
"execution_count": 19, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 19, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Rating</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>10.0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>9.5</td>\n </tr>\n <tr>\n <th>2</th>\n <td>9.0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>8.5</td>\n </tr>\n <tr>\n <th>4</th>\n <td>8.0</td>\n </tr>\n <tr>\n <th>5</th>\n <td>7.5</td>\n </tr>\n <tr>\n <th>6</th>\n <td>7.0</td>\n </tr>\n <tr>\n <th>7</th>\n <td>6.5</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Rating\n0 10.0\n1 9.5\n2 9.0\n3 8.5\n4 8.0\n5 7.5\n6 7.0\n7 6.5" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "#Use a variable q to store the column Rating as a dataframe\n\nq=df[['Rating']]\nq" | |
}, | |
{ | |
"execution_count": 20, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 20, | |
"metadata": {}, | |
"data": { | |
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Released</th>\n <th>Artist</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1982</td>\n <td>Michael Jackson</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1980</td>\n <td>AC/DC</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1973</td>\n <td>Pink Floyd</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1992</td>\n <td>Whitney Houston</td>\n </tr>\n <tr>\n <th>4</th>\n <td>1977</td>\n <td>Meat Loaf</td>\n </tr>\n <tr>\n <th>5</th>\n <td>1976</td>\n <td>Eagles</td>\n </tr>\n <tr>\n <th>6</th>\n <td>1977</td>\n <td>Bee Gees</td>\n </tr>\n <tr>\n <th>7</th>\n <td>1977</td>\n <td>Fleetwood Mac</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " Released Artist\n0 1982 Michael Jackson\n1 1980 AC/DC\n2 1973 Pink Floyd\n3 1992 Whitney Houston\n4 1977 Meat Loaf\n5 1976 Eagles\n6 1977 Bee Gees\n7 1977 Fleetwood Mac" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "#Assign the variable q to the dataframe that is made up of the column Released and Artist:\n\nq=df[['Released','Artist']]\nq" | |
}, | |
{ | |
"execution_count": 21, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"execution_count": 21, | |
"metadata": {}, | |
"data": { | |
"text/plain": "1980" | |
}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": "#Access the 2nd row and the 3rd column of df:\n\ndf.iloc[1,2]" | |
}, | |
{ | |
"execution_count": null, | |
"cell_type": "code", | |
"metadata": {}, | |
"outputs": [], | |
"source": "" | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.5", | |
"name": "python3", | |
"language": "python" | |
}, | |
"language_info": { | |
"mimetype": "text/x-python", | |
"nbconvert_exporter": "python", | |
"version": "3.5.5", | |
"name": "python", | |
"file_extension": ".py", | |
"pygments_lexer": "ipython3", | |
"codemirror_mode": { | |
"version": 3, | |
"name": "ipython" | |
} | |
} | |
}, | |
"nbformat": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment