Takes any number of arguments each should be the name

This preview shows page 17 - 20 out of 28 pages.

takes any number of arguments. Each should be the name or index of a column in the table. It returns a new table with only those columns in it. For example, the value of imdb.select("Year", "Decade") is a table with only the years and decades of each movie in imdb . Question 6.3. Use select to create a table with only the name, city, state, latitude (’y’), and longitude (’x’) of each market. Call that new table farmers_markets_locations . 17
In [308]: farmers_markets_locations = farmers_markets . select( "MarketName" , "city" , "State" , "y" farmers_markets_locations Out[308]: MarketName | city | State Caledonia Farmers Market Association - Danville | Danville | Vermont Stearns Homestead Farmers ' Market | Parma | Ohio 100 Mile Market | Kalamazoo | Michigan 106 S. Main Street Farmers Market | Six Mile | South Carolina 10th Steet Community Farmers Market | Lamar | Missouri 112st Madison Avenue | New York | New York 12 South Farmers Market | Nashville | Tennessee 125th Street Fresh Connect Farmers ' Market | New York | New York 12th & Brandywine Urban Farm Market | Wilmington | Delaware 14&U Farmers ' Market | Washington | District of Columbia ... (8536 rows omitted) In [309]: _ = ok . grade( ' q6_3 ' ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed 1.6.3 select is not column ! The method select is definitely not the same as the method column . farmers_markets.column( ' y ' ) is an array of the latitudes of all the markets. farmers_markets.select( ' y ' ) is a table that happens to contain only 1 column, the latitudes of all the markets. Question 6.4. Below, we tried using the function np.average to find the average latitude (’y’) and average longitude (’x’) of the farmers’ markets in the table, but we screwed something up. Run the cell to see the (somewhat inscrutable) error message that results from calling np.average on a table. Then, fix our code. In [312]: average_latitude = np . average(farmers_markets . column( ' y ' )) average_longitude = np . average(farmers_markets . column( ' x ' )) print ( "The average of US farmers ' markets ' coordinates is located at (" , average_lati The average of US farmers ' markets ' coordinates is located at ( 39.1864645235 , -90.9925808129 In [313]: _ = ok . grade( ' q6_4 ' ) 18
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Running tests --------------------------------------------------------------------- Test summary Passed: 1 Failed: 0 [ooooooooook] 100.0% passed 1.6.4 drop drop serves the same purpose as select , but it takes away the columns you list instead of the ones you don’t list, leaving all the rest of the columns. Question 6.5. Suppose you just didn’t want the "FMID" or "updateTime" columns in farmers_markets . Create a table that’s a copy of farmers_markets but doesn’t include those columns. Call that table farmers_markets_without_fmid . In [314]: farmers_markets_without_fmid = farmers_markets . drop( "FMID" , "updateTime" ) farmers_markets_without_fmid Out[314]: MarketName | Website Caledonia Farmers Market Association - Danville | Stearns Homestead Farmers ' Market | 100 Mile Market | 106 S. Main Street Farmers Market | . 10th Steet Community Farmers Market | nan 112st Madison Avenue | nan 12 South Farmers Market | 125th Street Fresh Connect Farmers ' Market | 12th & Brandywine Urban Farm Market | nan 14&U Farmers ' Market | nan

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture