[PYTHON] Anchoco for yourself

Due to changes in the site, I don't use it much Forget useful commands ... Since there are many things like that, it is a memo for myself.

Linux

Disk write performance check

 dd bs=1M count=1000 if=/dev/zero of=/HOGE/disktest oflag=direct

wget with cookies

wget -O [output] --load-cookies="./cookie.txt" [url]

GPU status reference

nvidia-smi

Line feed code messing around

perl -p -e 's/\n/\r\n/'

Port confirmation (2017/02/01 added)

lsof -i
lsof -i:[port]
netstat -antu

Python

Set cookie and get

import requests
cookies = {
    'aaa': '81',
    'bbb': 'xxx'
}
res = requests.get([url], cookies=cookies)

List comprehension

http://qiita.com/y__sama/items/a2c458de97c4aa5a98e7

nan judgment

math.iznan(xxx)

No line break print

print("hello", end="")

High speed for

for x in[None]*xxx
for x in[0]*xxx
for x in range(xxx)

Convert to date type (corrected 2017/02/01)

#Easy with pandas
pd.to_datetime('2015/1/1 10:00')

Time zone change (2017/02/01 added)

#Easy with pandas
pd.to_datetime('2015/1/1 10:00').tz_localize('GMT').tz_convert('Asia/Tokyo')
-> Timestamp('2015-01-01 19:00:00+0900', tz='Asia/Tokyo')

Look into modules and classes (Added 2017/02/01)

def pvars(_class):
    for _key in vars(_class).keys():
        print('[%s] %s' % (_key, vars(_class)[_key]))

Find the position of the maximum value in the DataFrame (Added 2017/03/22)

column_name = df.max().argmax()
index_name = df[column_name].argmax()
df.ix[index_name, column_name]

mongodb

Search by type

db.collection.find(xxx: {$type: 2})
    -Missing? 0
    - Double             1
    - String             2
    - Object             3
    - Array              4
    - Null              10
    - 32-bit integer    16
    - Timestamp         17
    - 64-bit integer    18

date type search

db.collection.find({xxx: {$gte:ISODate("2014-11-01T00:00:00Z")}})

Recommended Posts

Anchoco for yourself
Python code memo for yourself
LAMMPS command notes (completely for yourself)
Output elapsed time for data logging (for yourself)
Prepare sample data for text mining by yourself
Search for yourself from methods in Django's model