Boolean indexing and Matplotlib fun
Now let's look at how Boolean indexing can help us explore data visually in just a few lines of code. In this exercise, you'll practice many of the things you've learned - converting data from a dictionary into a useable pandas' DataFrame, indexing using Booleans, and then using matplotlib to visualize your data to learn about some relationships in the wildlife strikes data.
Deze oefening maakt deel uit van de cursus
Python for MATLAB Users
Oefeninstructies
- Convert the
strikesdictionary to a DataFrame. - Create a Boolean filter for
'Turbofan'in the'Engine'column. - Create a Boolean filter for
'Turboprop'in the'Engine'column. - Plot two scatter plots using
turbofanandturbopropto filter thestrikesdataset.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Create a dictionary and then a DataFrame from the dictionary
strikes = {'Date': date,'Speed': speed,'Height':height,'Engine':engine}
strikes = pd.____(strikes)
# Filter strikes by engine type
turbofan = strikes['Engine']=='____'
turboprop = strikes['____']=='____'
# Create scatter plot of speed and height for each engine type
plt.scatter(strikes[____]['Speed'],strikes[____]['Height'],label='Turbofan')
plt.scatter(strikes[____]['Speed'],strikes[____]['Height'],label='Turboprop')
plt.legend()
plt.xlabel('Strike speed (knots)')
plt.ylabel('Strike height (feet)')
plt.show()