Searching and Sorting Datasets with Python

Day 2: Getting the Python data base code

You can enlarge the textarea control by dragging the bottom right-hand corner. It can also be scrolled using the arrows.

Open a new Python project, click copy text button and paste the contents into the first frame.

Run the code in the first frame.

This code imports libraries from Python, reads in the spreadsheet file and prints the entire dataset.

You will have to adjust the location of the file in the code to your folder.

The default for printing is 10 items. pd.set_option display. max_rows line controls the number of items printed. The word none prints all of them.



Click copy text button and paste the contents into the next frame.

Click on the + icon in Jupyter Notebook to add a new frame

Save and run the code in the first two frames.

This code looks thru the Excel spreadsheet for all 19 foot boats and when it finds them it prints out True.

To see the actual 19 footers, paste in the following code into a new frame in Juputer Notebook. Save and run the code to see the first five 19 foot boats.

To see the tail of the dataset create a new framd and key in the following code.

boats_length_data.tail()

If we want to see all boats that are 19 feet in length, use the code below.

The default value of max_rows is 10. If set to ‘None‘ then it means all rows of the data frame. Set value of display.max_rows to None and pass it to set_option and this will display all rows from the data frame.


Click copy text button.

Click on the + icon in Jupyter Notebook to add a new frame

Paste the contents of the clipboard into the new frame.

Save and run the code in the first two frames.

Below is what you should expect when running this frame.




Click copy text button.

Click on the + icon in Jupyter Notebook to add a new frame

Paste the contents of the clipboard into the new frame.

Save and run the code in the first two frames.

You can do multiple searches in Python. Let's look for year manufactured and length. The code below looks at 19 foot boats manufactured in 2022 and 2023. Run it and see what you get.


Click copy text button.

Click on the + icon in Jupyter Notebook to add a new frame

Paste the contents of the clipboard into the new frame.

Save and run the code

Answer question 10 on the worksheet.

Make, type and power are column heads, and you can filter these out and show their contents using Python. The code below accomplishes just that. The head() function displays only the first five items.


Click copy text button.

Click on the + icon in Jupyter Notebook to add a new frame

Paste the contents of the clipboard into the new frame.

Save and run the code

Answer question 11 on the worksheet.