pandas pandas.DataFrame pandas.DataFrame.sample
pandas.Series pandas.Series.value_counts
vc = df['state'].value_counts()
print(vc)
print(type(vc))
# NY 2
# CA 2
# TX 1
# Name: state, dtype: int64
# <class 'pandas.core.series.Series'>
str str.replace
s = 'one two one two one'
print(s.replace(' ', '-'))
# one-two-one-two-one
s = 'one two one two one'
print(s.replace('one', 'XXX').replace('two', 'YYY'))
# XXX YYY XXX YYY XXX
s = 'abcdefghij'
print(s[:4] + 'XXX' + s[7:])
# abcdXXXhij
str.join
test = ['ab', 'c', 'de']
result = ''.join(test)
print(result)
# abcde4
str.split
str.ljust, str.rjust, str.center
s = 'abc'
s_rjust = s.rjust(8)
print(s_rjust)
# abc
print(s.center(8, '+'))
# ++abc+++
all
print(all([True, True, True]))
# True
any
print(any([True, False, False]))
# True
find, rfind
s = 'I am Sam'
print(s.find('Sam'))
# 5
print(s.find('XXX'))
# -1
list
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(a[::-1])
# [9, 8, 7, 6, 5, 4, 3, 2, 1]
"[]" Is removed when * list is output with *
[... for ... in ... if ...]
[... if ... else ... for ... in ...]
List=[1*i + 10*j + 100*k for k in range(2) for j in range(3) for i in range(4)]
print(List)
# [0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 100, 101, 102, 103, 110, 111, 112, 113, 120, 121, 122, 123]
init=[[1,2,3],[4,5],[6,7]]
[inner for outer in init for inner in outer]
# [1, 2, 3, 4, 5, 6, 7]
list.pop
List=["a","b","c","d","e","f"]
print(List.pop(1))
# b
print(List)
# ['a', 'c', 'd', 'e', 'f']
list.remove
List=["a","b","c","d","e","f"]
List.remove('d')
print(List)
# ['a', 'b', 'c', 'e', 'f']
del
List=["a","b","c","d","e","f"]
del List[1]
print(List)
# ['a', 'c', 'd', 'e', 'f']
list.insert
List=["a","b","c"]
List.insert(1,'z')
print(List)
# ['a', 'z', 'b', 'c']
set
l = [2, 2, 3, 1, 3, 4]
l_unique = list(set(l))
print(l_unique)
# [1, 2, 3, 4]
s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
print(s1 | s2)
# {1, 2, 3, 4}
&
-
^
ord
ord("a")
# 74
chr
chr(97)
# a
a,b,c,d = map(int, input().split())
print('TAKAHASHI' if b/a > d/c else 'AOKI' if b/a < d/c else 'DRAW')
float float.is_integer
f_i = 100.0
print(f_i.is_integer())
# True
numpy numpy.rehape
mask[:, :, idx] = mask_label.reshape(256, 1600, order='F')
numpy.nditer
numpy.where
a = np.arange(20, 0, -2)
print(a)
# [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
print(np.where(a < 10))
# [6, 7, 8, 9]
bisect
A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
print(A)
index = bisect.bisect_left(A, 3)
#2 (far left(Before)The insertion point of is returned)
eval
print(eval('1 + 2'))
# 3
reduce
a = [-1, 3, -5, 7, -9]
print reduce(lambda x, y: x + y, a)
# -5
map, filter
tqdm.tqdm
from tqdm import tqdm
for _ in tqdm(range(100)):
time.sleep(0.1)
Path.pathlib
from pathlib import Path
train_path = Path("../input/train_images/")
for img_name in train_path.iterdir():
img = Image.open(img_name)
seaborn
import seaborn as sns
sns.barplot(x=list(class_dict.keys()), y=list(class_dict.values()), ax=ax)
glob.glob
import glob
glob.glob('*.log')
# ['abc.log', 't_1.log', 't_2.log']
glob.glob(’t_*.log’)
# [t_1.log, t_2.log]
Recommended Posts