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 [2019/10/05 00:35] – [Pandas] christiansoftware:python [2021/12/14 20:36] (current) – [Pandas/Geopandas] christian
Line 40: Line 40:
  
  
-==== Pandas ====+==== 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]] +  * 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]] +  * 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]]+  * 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.   * [[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 )''