:%norm A*
% = for every line
norm = type the following commands
A* = Append `*` the end of current line
# 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') |
foo | bar | baz | |
---|---|---|---|
a | 1 | ||
b | 2 | ||
c | |||
4 | |||
e | 5 |
np.where(df.applymap(lambda x: x == '')) |
# 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"], |
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 |
$ docker save busybox > busybox.tar
$ ls -sh busybox.tar
2.7M busybox.tar
awk '{outfile=sprintf("fileName%02d.tsv",NR/100000+1);print > outfile}' fileName_of_really_big_textfile.tsv |
#!/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 |
# 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: |