r remove all string before : and keep : in r data frame code example

Example 1: how to get just the filename in python

import os
>>> base=os.path.basename('/root/dir/sub/file.ext')
>>> base
'file.ext'
>>> os.path.splitext(base)
('file', '.ext')
>>> os.path.splitext(base)[0]
'file'

Example 2: how to find rows with missing data in pandas

null_data = df[df.isnull().any(axis=1)]

Example 3: r remove all string before : in r data frame

> x <- 'aabb.ccdd'
> sub('.*', '', x)
[1] ""
> sub('bb.*', '', x)
[1] "aa"
> sub('.*bb', '', x)
[1] ".ccdd"
> sub('\\..*', '', x)
[1] "aabb"
> sub('.*\\.', '', x)
[1] "ccdd"

Example 4: how to print 2 list in python as table

a = ['a', 'b', 'c']
b = ['1', '0', '0']
res = "\n".join("{} {}".format(x, y) for x, y in zip(a, b))

Tags:

Java Example