python 常用命令

1. 查看包安装路劲

   以tensorflow为例
    import tensorflow as tf
    tf.__path__
    

2. 文件开头UTF-8

  -*- coding: <encoding name> -*- : # -*- coding: utf-8 -*-
  coding=<encoding name># coding=utf-8
  coding:<encoding name># coding: utf-8
 

3 apple lambda 使用多个if

course_feature['col_type'].apply(lambda x: 0 if re.search('varchar|char',x) is None else 1)

4. re

 (1)re.search

	str1 = 'textdsf'
	m = re.search("varchar|text", str1)
	f = 1
	if m is None:
	    f = 0

5. 通过值查看索引

(1) 列表
           ls = ['a', 'c', 'd']
           v ='a'
           I = ls.index(v)
           
(2)字典
        query_coder = {'12':'hello'}
        query_id = list(query_coder.keys())[list(query_coder.values()).index("hello")]

6. 通过map遍历迭代器或者集合

line=[1,3,467,567,345]
embedding.append(list(map(lambda x: round(float(x), 6), line[1:])))

7. numpy.argsort

从中可以看出argsort函数返回的是数组值从小到大的索引值
x = np.array([3, 1, 2])
np.argsort(x)
array([1, 2, 0])

8. 根据key找value

>>> dicxx = {'a':'001', 'b':'002'}
>>> list(dicxx.keys())[list(dicxx.values()).index("001")]
'a'

9. 脚本中跨文件夹引用文件

import sys
sys.path.append('../input/esim-script/ESIM') # from esim.data import Preprocessor 需要将esim的上一级目录加入path中
from esim.data import Preprocessor

python 命令行带argparse参数

!python ../input/esim-script/ESIM/scripts/fetch_data.py  --target_dir /kaggle/working/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值