Skip to content

Instantly share code, notes, and snippets.

@yoki
yoki / chap4-numpy.py
Created June 21, 2014 08:42
Chapter 4 Numpy
# -*- coding: utf-8 -*-
import numpy as np
#===========================================
#%% Index and element wise operation
#===========================================
#%% logical indexing
data = np.random.randn(7,4)
names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])
@yoki
yoki / find_replace.py
Last active December 10, 2022 05:17
Python String
s.index(s2, i, j) #Index of first occurrence of s2 in s after index i and before index j
s.find(s2) #Find and return lowest index of s2 in s
s.index(s2) #Return lowest index of s2 in s (but raise ValueError if not found)
s.replace(s2, s3) #Replace s2 with s3 in s
s.replace(s2, s3, count) #Replace s2 with s3 in s at most count times
s.rfind(s2) #Return highest index of s2 in s
s.rindex(s2) #Return highest index of s2 in s (raise ValueError if not found)
#===================================================
#Regexp
# csv.py: csv file io
# file.py: operation related to files
# directory.py: operation related to finding files and traveling directory
# file list:
# base.py
# element.py (how to get content of element)
# form.py
# javascript.py
# selector.py
# wait.py
@yoki
yoki / 0_XML.py
Last active June 17, 2022 17:44
Python XML
# xml document
# edit.py
# encode.py
# extract.py
# namespace.py
# search.py
# 10_basic.py
# 15_make_soup.py
# 20_search.py
# 25_navigation.py
# 30_edit.py
# 40_encoding.py
# 50_parse_only_part.py
@yoki
yoki / html2markdown.py
Created May 23, 2016 05:19
Convert html file to markdown
def html2markdown(self, html):
# convert html to markdown.
# specification:
# remove all tag exccept tags listed in the cleanbody._repl
# when p/div tags are in the table tag, markdown converter (htmlformatter)
# confuses. so it is removed
# we need following in the header
# import re, html2text
# from bs4 import BeautifulSoup
@yoki
yoki / 0_list_operation_iteration.py
Last active February 8, 2023 21:24
List operation/Control sequence/Repeat
# 1_loop.py
# 2_list_operation.py