meta data for this page

This is an old revision of the document!


Useful links and snippets regarding Python and Jupyter notebooks

Modules

iPython/Jupyter resources

Quick and dirty

  • # py3
    from urllib import parse
    parse.unquote("""TheURLString""")
    # or in py2.7
    import urllib
    urllib.unquote("theURL").decode('utf8')
  • Translate coordinate reference system from *.prj files to proj4-Syntax as required by QGIS using the gdal python module (via GIS on Stackexchange:
  • import sys
    from osgeo import osr
    prjtxt = """PROJCS["your_crs",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["the_prj"],PARAMETER["Central_Meridian",0.0],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Latitude_Of_Origin",0.0],PARAMETER["Standard_Parallel_1",-10],PARAMETER["Standard_Parallel_2",50],UNIT["Meter",1.0],AUTHORITY["me",123456]]"""
    srs = osr.SpatialReference()
    print 'Proj4 is: %s' % srs.ExportToProj4()
    Proj4 is: <string with proj4 parameters follows>

Pandas

* Invert a single column of a Pandas Dataframe: ``df.col2 = df.col2.values[::-1]`` via StackOverflow

  • Installing a new module in Enthough Canopy Light's distro on Windows: I managed to install the DBF module by navigating to the unzipped content downloaded in the Python console. Then I just typed %run setup.py install and the compiled module is then installed in the Canopy's User\Lib\site-packages directory. Easy.