Fetzen aus Python

»Links
»Group pandas DataFrame rows into lists
def as_grouped_lists(df, key_col, val_col):
     keys, values = df[[key_col, val_col]].sort_values(key_col).values.T
     ukeys, index = np.unique(keys, True)
     arrays = np.split(values, index[1:])
     return {k: list(v) for k, v in zip(ukeys, arrays)}

Source

»Slicing and Dicing

Als Referenz für mich.

a[:]     -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
a[:6]    -> ['a', 'b', 'c', 'd', 'e', 'f']    (head)
a[:-1]   -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
a[:-3]   -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
a[7:]    ->                                    ['h', 'i', 'j', 'k']
a[-3:]   ->                                         ['i', 'j', 'k']    (tail)
a[3:8]   ->                ['d', 'e', 'f', 'g', 'h']
a[3:-1]  ->                ['d', 'e', 'f', 'g', 'h', 'i', 'j']
a[-3:-1] ->                                         ['i', 'j']
a[::-1]  -> ['k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']    (reverse list)
a[::2]   -> ['a', 'c', 'e', 'g', 'i', 'k']    (every 2nd item)
a[::-2]  -> ['k', 'i', 'g', 'e', 'c', 'a']    (every 2nd item start at end, move backwards)