python数据科学速查表_Python数据科学速查表:中级

python数据科学速查表

The printable version of this cheat sheet

该备忘单的可打印版本

The tough thing about learning data is remembering all the syntax. While at Dataquest we advocate getting used to consulting the Python documentation, sometimes it’s nice to have a handy reference, so we’ve put together this cheat sheet to help you out!

学习数据的困难之处在于记住所有语法。 在Dataquest时,我们提倡习惯于查阅Python文档 ,有时可以得到一些方便的参考,这很高兴,因此我们整理了这份备忘单,可以为您提供帮助!

This cheat sheet is the companion to our Python Basics Data Science Cheat Sheet

该备忘单是我们的Python基础数据科学备忘单的伴侣

If you’re interested in learning Python, we have a free Python Programming: Beginner course which can start you on your data science journey.

如果您对学习Python感兴趣,我们有一个免费的Python编程:入门课程,可以帮助您开始数据科学之旅。

关键基础知识,打印和获得帮助 (Key Basics, Printing and Getting Help)

This cheat sheet assumes you are familiar with the content of our Python Basics Cheat Sheet

该备忘单假定您熟悉我们的Python基础备忘单的内容

ss A Python string variable Python字符串变量
ii A Python integer variable Python整数变量
ff A Python float variable Python浮点变量
ll A Python list variable Python列表变量
dd A Python dictionary variable Python字典变数

清单 (Lists)

l.pop(3)l.pop(3) l and deletes it from the listl的第四项并将其从列表中删除
l.remove(x)l.remove(x) l that is equal to l中等于xx的第一项
l.reverse()l.reverse() ll项目的顺序
l[1::2]l[1::2] l, commencing from the l ,从开始1st item1日项目
l[-5:]l[-5:] ll中的最后5个项目

弦乐 (Strings)

s.lower()s.lower() ss的小写版本
s.title()s.title() s with the first letter of every word capitalizeds ,首字母大写
"23".zfill(4)"23".zfill(4) "0023" by left-filling the string with 0左填充字符串以使其长度为0’s to make it’s length 4来返回4."0023"
s.splitlines()s.splitlines() Returns a list by splitting the string on any newline characters. 通过将字符串拆分为任何换行符来返回列表。
Python strings share some common methods with listsPython字符串与列表共享一些常用方法  
s[:5]s[:5] 5 characters of s的前s5字符
"fri" + "end""fri" + "end" "friend""friend"
"end" in s"end" in s True if the substring s找到子字符串"end" is found in "end"则返回sTrue

范围 (Range)

Range objects are useful for creating sequences of integers for looping.

范围对象对于创建整数序列进行循环很有用。

range(5)range(5) 0 to 044的序列
range(2000,2018)range(2000,2018) 2000 to 200020172017的序列
range(0,11,2)range(0,11,2) 0 to 010, with each item incrementing by 10的序列,每一项增加22
range(0,-10,-1)range(0,-10,-1) 0 to 0-9-9的序列
list(range(5))list(range(5)) 0 to 044的列表

辞典 (Dictionaries)

max(d, key=d.get)max(d, key=d.get) dd最大值的键
min(d, key=d.get)min(d, key=d.get) dd最小值的键

套装 (Sets)

my_set = set(l)my_set = set(l) set object containing the l unique values from 唯一值的lset对象
len(my_set)len(my_set) Returns the number of objects in my_set (or, the number of unique values from l) 返回my_set中对象的my_set (或l唯一值的数量)
a in my_seta in my_set True if the value my_set存在值a exists in a则返回my_setTrue

常用表达 (Regular expressions)

import reimport re Import the Regular Expressions module 导入正则表达式模块
re.search("abc",s)re.search("abc",s) match object if the regex s找到正则表达式"abc" is found in "abc" ,则返回s, otherwise match对象,否则返回NoneNone
re.sub("abc","xyz",s)re.sub("abc","xyz",s) "abc" are replaced by "abc"匹配的实例都将替换为"xyz""xyz"

清单理解 (List comprehension)

A one-line expression of a for loop

for循环的单行表达式

[i ** 2 for i in range(10)][i ** 2 for i in range(10)] 0 to 099的值的平方的列表
[s.lower() for s in l_strings][s.lower() for s in l_strings] l_strings, with each item having had the l_strings ,每一项都应用.lower() method applied.lower()方法
[i for i in l_floats if i < 0.5][i for i in l_floats if i < 0.5] l_floats that are less than l_floats返回小于0.50.5

循环功能 (Functions for looping)

for i, value in enumerate(l):
    print("The value of item {} is {}".format(i,value))
for i, value in enumerate(l):
    print("The value of item {} is {}".format(i,value))
l, printing the index location of each item and its valuel ,打印每个项目的索引位置及其值
l_one and l_onel_two and print each valuel_two并打印每个值
while x < 10:
    x += 1
while x < 10:
    x += 1
x is no longer less than x的值不再小于1010

约会时间 (Datetime)

import datetime as dtimport datetime as dt datetime moduledatetime模块
now = dt.datetime.now()now = dt.datetime.now() datetime object representing the current time to datetime对象到nownow
wks4 = dt.datetime.timedelta(weeks=4)wks4 = dt.datetime.timedelta(weeks=4) timedelta object representing a timespan of 4 weeks to timedelta对象分配给wks4wks4
now - wks4now - wks4 datetime object representing the time 4 weeks prior to datetime对象表示时间前4周nownow
newyear_2020 = dt.datetime(year=2020, month=12, day=31)newyear_2020 = dt.datetime(year=2020, month=12, day=31) datetime object representing December 25, 2020 to datetime对象分配给newyear_2020newyear_2020
newyear_2020.strftime("%A, %b %d, %Y")newyear_2020.strftime("%A, %b %d, %Y") "Thursday, Dec 31, 2020""Thursday, Dec 31, 2020"
dt.datetime.strptime('Dec 31, 2020',"%b %d, %Y")dt.datetime.strptime('Dec 31, 2020',"%b %d, %Y") datetime object representing December 31, 2020datetime对象

随机 (Random)

import randomimport random random modulerandom模块
random.random()random.random() 0.0 and 0.01.01.0之间的随机浮点数
random.randint(0,10)random.randint(0,10) 0 and 01010之间的随机整数
random.choice(l)random.choice(l) ll

计数器 (Counter)

from collections import Counterfrom collections import Counter Counter classCounter
c = Counter(l)c = Counter(l) Counter (dict-like) object with the counts of each unique item from Counter (类似dict的对象),其对象中每个唯一项的计数从l, to lcc
c.most_common(3)c.most_common(3) ll最常见的3个项目

尝试/除外 (Try/Except)

Catch and deal with errors

捕捉并处理错误

l_ints = [1, 2, 3, "", 5]

l_ints = [1, 2, 3, "", 5]

l_intsl_ints
l_ints to a float, catching and handling l_ints每个值转换为浮点数,捕获并处理ValueError: could not convert string to float: where values are missing.ValueError: could not convert string to float:缺少值的地方。

下载此备忘单的可打印版本 (Download a printable version of this cheat sheet)

翻译自: https://www.pybloggers.com/2017/08/python-cheat-sheet-for-data-science-intermediate/

python数据科学速查表

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值