Skip to content

Instantly share code, notes, and snippets.

Aquabiota Solutions AB mapcloud

Block or report user

Report or block mapcloud

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vim_add_to_end_of_each_line.md

VIM

:%norm A*

Description

%       = for every line
norm    = type the following commands
A*      = Append `*` the end of current line
@mapcloud
mapcloud / pandas_df_rows_into_columns_by_category.py
Created Oct 9, 2017
pandas data frame rows into columns based by category. Kind of transposing the data.
View pandas_df_rows_into_columns_by_category.py
# Source: https://stackoverflow.com/questions/39635993/how-to-convert-pandas-dataframe-rows-into-columns-based-on-category
# convert the module variables into columns and group by the id. So something like:
# Example
ls = [{'count':5, 'module':'payroll', 'id':2}, {'count': 53, 'module': 'general','id':2}, {'id': 5,'count': 35, 'module': 'tax'}, ]
df = pd.DataFrame.from_dict(ls)
# Solution
# You can use groupby by columns which first create new index and last column. then need aggreagate some way - I use mean, then convert one column DataFrame to Series by DataFrame.squeeze (then is not necessary remove top level of Multiindex in columns) and reshape by unstack. Last add_suffix to column name
df = df.groupby(['id','module']).mean().squeeze().unstack().add_suffix('_count')
@mapcloud
mapcloud / find_empty_string_values_in_df.py
Created Jul 28, 2017
Finding values which are empty strings with pandas and applymap
View find_empty_string_values_in_df.py
np.where(df.applymap(lambda x: x == ''))
@mapcloud
mapcloud / pandas_to_geojson.py
Created Jul 28, 2017
Pandas to GeoJSON (Multiples points + features) with Python
View pandas_to_geojson.py
# Real source heroes here: https://gis.stackexchange.com/questions/220997/pandas-to-geojson-multiples-points-features-with-python?rq=1
import json
import simplekml
import geojson
import pandas as pd
def data2kml(df):
kml = simplekml.Kml()
df.apply(lambda X: kml.newpoint(
name=X["name"],
@mapcloud
mapcloud / compassbearing.py
Created Jul 27, 2017 — forked from jeromer/compassbearing.py
compass bearing between two points in Python
View compassbearing.py
def calculate_initial_compass_bearing(pointA, pointB):
"""
Calculates the bearing between two points.
The formulae used is the following:
θ = atan2(sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))
:Parameters:
- `pointA: The tuple representing the latitude/longitude for the
@mapcloud
mapcloud / docker-housekeeping.md
Last active Dec 18, 2017
How to Delete All <none>, Untagged and dangling Docker Containers and Images?
View docker-housekeeping.md

Transfer docker image to non-internet-connected machine

See Docker save docs

Create a backup that can then be used with docker load

$ docker save busybox > busybox.tar

$ ls -sh busybox.tar

2.7M busybox.tar
@mapcloud
mapcloud / bash
Created Jul 10, 2017
How to split a very large text file into smaller files
View bash
awk '{outfile=sprintf("fileName%02d.tsv",NR/100000+1);print > outfile}' fileName_of_really_big_textfile.tsv
@mapcloud
mapcloud / custom_gremlin_step_pyorient.py
Created Jun 8, 2017 — forked from lebedov/custom_gremlin_step_pyorient.py
Define and use custom step in Gremlin via pyorient.
View custom_gremlin_step_pyorient.py
#!/usr/bin/env python
"""
Define and use custom step in Gremlin via pyorient.
"""
from pyorient.ogm import Graph, Config
from pyorient.ogm.declarative import declarative_node, declarative_relationship
from pyorient.ogm.property import String
@mapcloud
mapcloud / unique_list_in_list_of_dictionaries.py
Last active Apr 29, 2017
Python: Creates an unique list for a given list of dictionaries. Useful to remove duplicates of dictionaries within a list.
View unique_list_in_list_of_dictionaries.py
# Credits to: http://stackoverflow.com/questions/11741876/getting-unique-values-from-a-list-of-dict
import ast
def unique_list_in_list_of_dictionaries(content_list: list())->list:
"""
content_list = [{'A':1, 'B':1, 'C':1},
{'A':1, 'B':1, 'C':1},
{'A':2, 'B':2, 'C':2}
{'A':3, 'B':2, 'C':1}
{'A':3, 'B':2, 'C':1}]
:returns:
You can’t perform that action at this time.