Skip to main content

Viewing the data

  • Chapter
  • First Online:
Advanced Python Development
  • 2834 Accesses

Abstract

Chapter 9 sees us return to Jupyter to use its features for data visualization and easy user interaction. We will look at how to use our asynchronous functions with widgets in Jupyter notebooks as well as advanced use of iterators and ways of implementing complex data types.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Size is calculated using sys.getsizeof(...). This does not include the size of attributes on an object, which can be found with sys.getsizeof(obj.__dict__) for simple objects.

  2. 2.

    Estimated using timeit.timeit(...), as follows:

    setup = """ import datetime import uuid from sqlalchemy.util._collections import lightweight_named_tuple result = lightweight_named_tuple("result", ["id", "collected_at", "sensor_name", "deployment_id", "data",]) data = (1, datetime.datetime.now(), "Example", uuid.uuid4(), None) """ timeit.timeit("result(data)", setup)

  3. 3.

    The “o” style specifies a circular marker and no line. The string can contain a marker type, a line style, and a color. *r would plot red stars, - is a line in the default color with no markers, s--m is magenta squares connected by a dashed line, etc. The additional resource list in this chapter contains a link to the full specification.

  4. 4.

    zip(*iterables) flips the way that an iterable of iterables is split up. I find it easiest to imagine this as equivalent to rotating a spreadsheet. If your input iterables are ["Matt", "Leeds"], ["Jesse", "Seattle"], and ["Nejc", "Ljubljana"], you can imagine that as being equivalent to a spreadsheet where the names are in column A and the cities in column B. In that case, Matt is row 1, Jesse is row 2, and Nejc is row 3. tuple(zip(*names_and_cities)) reads out the columns in order, so it would be (('Matt', 'Jesse', 'Nejc'), ('Leeds', 'Seattle', 'Ljubljana')).

  5. 5.

    I’d recommend not adding a commit() call, as this will allow changes to the database to be rolled back between tests.

  6. 6.

    The temperature sensor is intended as a measure of ambient temperature. If we write a new sensor type to collect a different type of temperature data, we may need to reconsider this filter.

  7. 7.

    Specifically, IPython tries to compile the cell to bytecode and checks for a SyntaxError. If there is a SyntaxError, it will wrap the code in a coroutine and try again.

  8. 8.

    asyncio.run(...) is not re-entrant: calls cannot be nested.

  9. 9.

     Mypy would word the error as error: Argument 2 to "add_number_from_callback" has incompatible type "Callable[[], Coroutine[Any, Any, int]]"; expected "Callable[[], int]"

  10. 10.

    https://wiki.openstreetmap.org/wiki/Mercator#Python_implementation

  11. 11.

    The code used to extract these is as follows. The data is from the www.naturalearthdata.com data set.

    import fiona path = "ne_10m_admin_0_countries.shp" shape = fiona.open(path) countries = tuple(shape) UK = [country for country in countries if country['properties']['ADMIN'] == "United Kingdom"][0] coastlines = UK['geometry']['coordinates'] by_complexity = sorted(coastlines, key=lambda coords: len(coords[0])) gb_boundary = by_complexity[-1][0]

    This was omitted from the Jupyter notebook to reduce the dependencies needed to use it. In practice, this function would be used rather than literal tuples.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Matthew Wilkes

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Wilkes, M. (2020). Viewing the data. In: Advanced Python Development. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-5793-7_9

Download citation

Publish with us

Policies and ethics