software:python [PaleoEarthLabs wiki]

PaleoEarthLabs wiki

One bucket of limited wisdom

Site Tools


software:python

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software:python [2018/09/11 19:58]
christian
software:python [2019/10/05 01:53] (current)
christian [Pandas/Geopandas]
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 33: Line 38:
 Proj4 is: <string with proj4 parameters follows> Proj4 is: <string with proj4 parameters follows>
 </​code>​ </​code>​
 +
 +
 +==== 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]]
  
  
Line 43: Line 59:
   * 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}}
  
software/python.1536688701.txt.gz · Last modified: 2018/09/11 19:58 by christian