Commit 2f978b60 authored by George Mount's avatar George Mount
Browse files

update files

parent f6d3aae4
%% Cell type:markdown id: tags:
### Drill
Take a shot at assigning an array and finding its square root using this aliasing method.
%% Cell type:code id: tags:
``` python
# Import and alias the module
import ___ ___ ___
# Create an array
my_new_array = ___.___([36, 49, 64, 81])
# Take its square root
np.___(___)
```
%% Cell type:code id: tags:
``` python
# Import and alias the module
import numpy as np
# Create an array
my_new_array = np.array([36, 49, 64, 81])
# Take its square root
np.sqrt(my_new_array)
```
%% Cell type:markdown id: tags:
# DRILL
Practice your `numpy` skills by operating on a large array.
I will get you started; complete the operations based on what the comments are asking for.
%% Cell type:code id: tags:
``` python
# Don't worry about this part -- I am reading the file into Python.
# You will learn how to read files into Python in the next unit.
my_array = np.genfromtxt('numpy-drill.csv')
print(my_array)
my_array
```
%% Output
[47. 21. 23. 24. 45. 6. 30. 43. 45. 23. 2. 46. 4. 34. 42. 2. 47. 14.
18. 9. 50. 34. 12. 24. 42. 24. 3. 39. 17. 15. 37. 18. 46. 25. 9. 41.
45. 34. 22. 26. 27. 44. 28. 4. 15. 31. 3. 39. 15. 23. 5. 27. 11. 25.
16. 11. 2. 43. 35. 45. 27. 48. 44. 20. 4. 21. 8. 48. 29. 20. 15. 20.
37. 17. 6. 13. 39. 25. 5. 11. 4. 20. 47. 9. 2. 8. 44. 40. 8. 1.
45. 26. 43. 10. 22. 24. 3. 48. 29. 49.]
%% Cell type:code id: tags:
``` python
# What is the shape of this array?
# This also tells us how many dimensions there are --
# one number means one dimension
my_array.shape
```
%% Output
(100,)
%% Cell type:code id: tags:
``` python
# What is its datatype?
my_array.dtype
```
%% Output
dtype('float64')
%% Cell type:code id: tags:
``` python
# Reshape this result into a 10x10 array
my_array = np.reshape(my_array, (10, 10))
```
%% Cell type:code id: tags:
``` python
# What is the shape of our array now?
my_array.shape
```
%% Output
(10, 10)
%% Cell type:code id: tags:
``` python
# Take the sqrt of this array
my_array = np.sqrt(my_array)
my_array
```
%% Output
array([[2.6183305 , 2.14069514, 2.1899387 , 2.21336384, 2.59002006,
1.56508458, 2.34034732, 2.5607496 , 2.59002006, 2.1899387 ],
[1.18920712, 2.60429069, 1.41421356, 2.4147364 , 2.5457299 ,
1.18920712, 2.6183305 , 1.93433642, 2.05976714, 1.73205081],
[2.65914795, 2.4147364 , 1.86120972, 2.21336384, 2.5457299 ,
2.21336384, 1.31607401, 2.4989994 , 2.03054318, 1.96798967],
[2.46632571, 2.05976714, 2.60429069, 2.23606798, 1.73205081,
2.53043953, 2.59002006, 2.4147364 , 2.16573677, 2.25810086],
[2.27950706, 2.57550958, 2.30032663, 1.41421356, 1.96798967,
2.35961106, 1.31607401, 2.4989994 , 1.96798967, 2.1899387 ],
[1.49534878, 2.27950706, 1.82116029, 2.23606798, 2. ,
1.82116029, 1.18920712, 2.5607496 , 2.43229928, 2.59002006],
[2.27950706, 2.63214803, 2.57550958, 2.11474253, 1.41421356,
2.14069514, 1.68179283, 2.63214803, 2.32059579, 2.11474253],
[1.96798967, 2.11474253, 2.46632571, 2.03054318, 1.56508458,
1.89882892, 2.4989994 , 2.23606798, 1.49534878, 1.82116029],
[1.41421356, 2.11474253, 2.6183305 , 1.73205081, 1.18920712,
1.68179283, 2.57550958, 2.51486686, 1.68179283, 1. ],
[2.59002006, 2.25810086, 2.5607496 , 1.77827941, 2.16573677,
2.21336384, 1.31607401, 2.63214803, 2.32059579, 2.64575131]])
%% Cell type:code id: tags:
``` python
# Access the element in the fourth row
# and second column of the array
my_array[3,1]
```
%% Output
2.0597671439071177
%% Cell type:code id: tags:
``` python
# What is the shape of this array?
# This also tells us how many dimensions there are --
# one number means one dimension
my_array.___
```
%% Cell type:code id: tags:
``` python
# What is its datatype?
___
```
%% Cell type:code id: tags:
``` python
# Reshape this result into a 10x10 array
my_array = np.reshape(___, ___)
```
%% Cell type:code id: tags:
``` python
# What is the shape of our array now?
___
```
%% Cell type:code id: tags:
``` python
# Take the sqrt of this array
my_array = np.___(___)
my_array
```
%% Cell type:code id: tags:
``` python
# Access the element in the fourth row
# and second column of the array
my_array___
```
%% Cell type:markdown id: tags:
# DRILL
Practice reading in and exploring the two files in the `practice` folder.
1. `largest-us-cities.csv`: Find the data types and dimensions of this DataFrame. Also print out the first five rows.
2. `chicago-big-ten.xlsx`: The worksheet you're interested in is called `alumni`. Get the column names and run the descriptive statistics.
%% Cell type:code id: tags:
``` python
big_cities = pd.read_csv('practice/largest-us-cities.csv')
```
%% Cell type:code id: tags:
``` python
# Data types
print(big_cities.dtypes)
big_cities.dtypes
```
# Dimensions
print(big_cities.shape)
%% Cell type:code id: tags:
# First five rows
print(big_cities.head())
``` python
# Dimensions
big_cities.shape
```
%% Output
%% Cell type:code id: tags:
city object
population int64
pop_change float64
land_area float64
dtype: object
(10, 4)
city population pop_change land_area
0 New York 8336817 0.0198 301.5
1 Los Angeles 3979576 0.0493 468.7
2 Chicago 2693976 -0.0006 227.3
3 Houston 2320268 0.1048 637.5
4 Phoenix 1680992 0.1628 517.6
``` python
# First five rows
big_cities.head()
```
%% Cell type:code id: tags:
``` python
chicago = pd.read_excel('practice/chicago-big-ten.xlsx')
chicago
```
%% Output
Empty DataFrame
Columns: [GO BUCKEYES!]
Index: []