# Problem 1¶

Import NumPy under the alias np.

In :
import numpy as np


# Problem 2¶

Import pandas under the alias pd.

In :
import pandas as pd


# Problem 3¶

Given the following NumPy array data, create a pandas DataFrame named first_data_frame that contains the same elements. Print the DataFrame to make sure the operation executed successfully.

In :
data = np.round(np.random.randn(5,5),1)

In :
#Solution goes here
first_data_frame = pd.DataFrame(data)
first_data_frame


# Problem 4¶

Assign the values of row_labels to the index of first_data_frame. Print the DataFrame to make sure the operation executed successfully.

Hint: It will be easier to overwrite first_data_frame by using another pd.DataFrame method.

In :
row_labels = ['one','two','three','four','five']

In :
#Solution goes here
first_data_frame = pd.DataFrame(data,row_labels)
first_data_frame

Out:
0 1 2 3 4
one -1.9 1.8 0.6 0.0 1.1
two 2.3 -2.1 -0.3 -1.8 -0.6
three 0.7 0.4 -1.0 -0.7 0.3
four 0.8 0.5 -0.7 0.0 0.2
five 1.7 1.0 -1.3 1.8 1.3

# Problem 5¶

Assign the values of column_labels to the columns of first_data_frame. Note that there are two main ways to do this - you are free to chose the method of your choice. Print the DataFrame to make sure the operation executed successfully.

In :
column_labels = ['alpha','beta','charlie','delta','echo']

In :
#Solution goes here
first_data_frame.columns = column_labels
first_data_frame

Out:
alpha beta charlie delta echo
one -1.9 1.8 0.6 0.0 1.1
two 2.3 -2.1 -0.3 -1.8 -0.6
three 0.7 0.4 -1.0 -0.7 0.3
four 0.8 0.5 -0.7 0.0 0.2
five 1.7 1.0 -1.3 1.8 1.3

# Problem 6¶

Create a pandas Series named my_series that contains the values from row alpha of first_data_frame. Print my_series to make sure the operation executed successfully.

In :
#Solution goes here
my_series = first_data_frame['alpha']
my_series

Out:
one     -1.9
two      2.3
three    0.7
four     0.8
five     1.7
Name: alpha, dtype: float64

# Problem 7¶

Create a new DataFrame called second_data_frame that is equal to first_data_frame but without row one. Print second_data_frame to make sure the operation executed successfully.

In :
#Solution goes here
second_data_frame = first_data_frame.drop('one')
second_data_frame

Out:
alpha beta charlie delta echo
two 2.3 -2.1 -0.3 -1.8 -0.6
three 0.7 0.4 -1.0 -0.7 0.3
four 0.8 0.5 -0.7 0.0 0.2
five 1.7 1.0 -1.3 1.8 1.3

# Problem 8¶

Create a new DataFrame called third_data_frame that is equal to second_data_frame, but without row charlie. Print third_data_frame to make sure the operation executed successfully.

In :
#Solution goes here
third_data_frame = second_data_frame.drop('charlie', axis=1)
third_data_frame

Out:
alpha beta delta echo
two 2.3 -2.1 -1.8 -0.6
three 0.7 0.4 -0.7 0.3
four 0.8 0.5 0.0 0.2
five 1.7 1.0 1.8 1.3

# Problem 9¶

Create a variable called row_two that is equal to row two from third_data_frame. Print row_two to make sure the operation executed successfully.

In :
#Solution goes here
row_two = third_data_frame.loc['two']
row_two

Out:
alpha    2.3
beta    -2.1
delta   -1.8
echo    -0.6
Name: two, dtype: float64

# Problem 10¶

Print the shape of new_data.

In :
new_data = np.round(np.random.randn(5,5),1)

In :
#Solution goes here
new_data.shape

Out:
(5, 5)

# Problem 11¶

Print a DataFrame that contains boolean values that indicate whether the elements of new_data are greater than 1.

In :
pd.DataFrame(new_data > 1)

Out:
0 1 2 3 4
0 True True True False False
1 False False False False True
2 False False False True False
3 True False False False False
4 False False False True False

# Problem 12¶

Print a NumPy array that contains only the elements of new_data that are greater than 1.

In :
new_data[new_data > 1]

Out:
array([2.3, 1.5, 1.6, 1.2, 2.2, 1.1, 1.7])
In [ ]:


In [ ]:


In [ ]: