Question: Need 12-17 please. Setting up a DataFrame 1) First import pandas: In [ ]: import pandas as pd 2) Load the data provided into a
Need 12-17 please.
Setting up a DataFrame
1) First import pandas:
In [ ]:
import pandas as pd
2) Load the data provided into a dictionary in the notebook's memory.
In [ ]:
web_stats = {'Day':[1,2,3,4,5,6], 'Visitors':[43,53,34,45,64,34],
'Bounce_Rate':[65,75,62,64,54,66]} # single line broken down to several
3) Convert the dictionary to a DataFrame.
In [ ]:
df = pd.DataFrame(web_stats)
4) Print the dataframe.
In [ ]:
print(df)
Viewing Specific DataFrame sections
Rows
5) Write the code to print all the rows.
In [ ]:
df
6) Write the code to prints only the first three rows of the DataFrame.
In [ ]:
print(df.head(3))
7) Write the code to print only the last row of the DataFrame.
In [ ]:
print(df.tail(1))
8) Enter in the following what is the default number of rows for the head and the tail.
Place answer here in this cell: 5
Columns
9a) Write the code to print only the 'Visitor' column using Column Name method.
In [ ]:
print(df['Visitors'])
9b) Write the code to print only the 'Visitor' column using DataFrame Attribute method.
In [ ]:
print(df.Visitors)
10a) Write the code to print only the 'Bounce_Rate' column using Column Name method.
In [ ]:
print(df['Bounce_Rate'])
10b) Write the code to print only the 'Bounce_Rate' column using Dataframe attribute method.
In [ ]:
print(df.Bounce_Rate)
11) Write the code to print only the 'Bounce_Rate' and 'Visitors' columns.
In [ ]:
print(df[['Bounce_Rate', 'Visitors']])
Indexing
12) Create another Dataframe by copying the original Dataframe while simultaneosly making the 'Date' column as the index and leaving the original Dataframe unchanged.
In [ ]:
13) Print both the original Dataframe and new Dataframe. (The original Dataframe should have no index and new should have 'Date' as the index).
In [ ]:
14) Write the code to set 'Day' permanently as the index in the original Dataframe.
In [ ]:
13) Write the code to print the original Dataframe. ('Day' should be an index)
In [ ]:
Simple Plotting
15) Import Matplotlib and set the style to ggplot
In [ ]:
16) Create a graph using all data.
In [ ]:
17) Create a graph using only the 'Visitor' column.
In [ ]:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
