meta data for this page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
software:python [2018/03/04 21:13] christiansoftware:python [2021/12/14 20:36] (current) – [Pandas/Geopandas] christian
Line 1: Line 1:
 Useful links and snippets regarding Python and Jupyter notebooks Useful links and snippets regarding Python and Jupyter notebooks
 +
 +====== Modules ======
 +
 +  * The uncompromising Python code formatter [[https://black.readthedocs.io/en/stable/]] and on Github: [[https://github.com/psf/black]]
 +
  
 ===== iPython/Jupyter resources ===== ===== iPython/Jupyter resources =====
Line 8: Line 13:
   * [[http://matplotlib.org/examples/color/colormaps_reference.html|Matplotlib colormaps]] and [[https://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib| how to normalise a colormap]]   * [[http://matplotlib.org/examples/color/colormaps_reference.html|Matplotlib colormaps]] and [[https://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib| how to normalise a colormap]]
   * [[https://maxmasnick.com/projects/scipy-tips/|Max Masnick's Dat science Python snippets]]   * [[https://maxmasnick.com/projects/scipy-tips/|Max Masnick's Dat science Python snippets]]
 +  * [[https://realpython.com/python-matplotlib-guide/|MatPlotLib guide]]
  
  
Line 34: Line 40:
  
  
 +==== Pandas/Geopandas ====
 +
 +  * Invert a single column of a Pandas Dataframe: ''df.col2 = df.col2.values[::-1]'' [[https://stackoverflow.com/questions/46244235/invert-a-single-column-in-a-dataframe|via StackOverflow]]
 +  * Joining multiple overlapping column names from multiple dataframes: ''pd.concat(data, axis=1)'' [[https://stackoverflow.com/questions/13003769/joining-multiple-dataframes-with-pandas-with-overlapping-column-names|via StackOverflow]]
 +  * Cross-section indexing of a multi-indexed dataframe - using levels: ''concatdf.xs('MIndexValue', level='MIndexName')'' - [[http://pandas-docs.github.io/pandas-docs-travis/user_guide/advanced.html#advanced-xs|via Pandas documentation]] and [[https://stackoverflow.com/questions/24435788/using-loc-with-a-multiindex-in-pandas#24436783|StackOverflow]]
 +  * [[https://stackoverflow.com/questions/53645882/pandas-merging-101|Pandas merging 101]] on StackOverflow.
 +  * Going from a regular dataframe to geopandas data frame: ''gdf = geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))'' -- [[https://geopandas.readthedocs.io/en/latest/gallery/create_geopandas_from_pandas.html|via Geopandas doc]]
 +  * Obtaining unique values for Multi-index levels: ''concatdf.index.unique(level=1)''
 +  * Drop a level of multi-index into a column: ''df.reset_index(level=[...])'' - via [[https://stackoverflow.com/questions/20110170/turn-pandas-multi-index-into-column|StackOverflow]]
 +  * Generating a column with conditional values based on an existing column [[https://datagy.io/pandas-conditional-column/|via datagy.io]]: ''myDict = { 'a': 1, 'b': 2, 'c': 3}'', ''df[newCol] = df[oldCol].map( myDict )''
  
  
 ===== Stuff related to modules ===== ===== Stuff related to modules =====
  
-  * [[osgeo.ogr]]+  * [[https://gdal.org/python/osgeo.ogr-module.html|osgeo.ogr]]
   * [[http://effbot.org/zone/import-confusion.htm|Importing modules - effbot's import confusion]]   * [[http://effbot.org/zone/import-confusion.htm|Importing modules - effbot's import confusion]]
   * Installing a new module in Enthough Canopy Light's distro on Windows: I managed to install the [[https://pypi.python.org/pypi/dbf|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.   * Installing a new module in Enthough Canopy Light's distro on Windows: I managed to install the [[https://pypi.python.org/pypi/dbf|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.
  
-{{tag> Python Programming Jupyter iPython notebooks}}+{{tag> Python Programming Jupyter iPython notebooks pandas}}