python 桌面备忘录_Python数据科学备忘单

python 桌面备忘录

The printable version of this cheat sheet

该备忘单的可打印版本

It’s common when first learning Python for Data Science to have trouble remembering all the syntax that you need. 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!

第一次学习Python for Data Science时,通常很难记住您需要的所有语法。 在Dataquest时,我们提倡习惯于查阅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)

x = 3x = 3 3 to the variable 3赋给变量xx
print(x)print(x) xx的值
type(x)type(x) Return the type of the variable x (in this case, int for integer) 返回变量x的类型(在这种情况下, intint
help(x)help(x) str data typestr数据类型的文档
help(print)help(print) print() functionprint()函数的文档

读取文件 (Reading Files)

f = open("my_file.txt", "r")
file_as_string = f.read()
f = open("my_file.txt", "r")
file_as_string = f.read()
my_file.txt and assign its contents to my_file.txt并将其内容分配给singsing
my_dataset.csv and assign its data to the list of lists my_dataset.csv并将其数据分配给列表csv_as_listcsv_as_list的列表

弦乐 (Strings)

s = "hello"s = "hello" "hello" to the variable "hello"分配给变量ss
s = """She said,
"there's a good idea."
"""
s = """She said,
"there's a good idea."
"""
s. Also used to create strings that contain boths 。 也用于创建同时包含" and "' characters.'字符的字符串。
len(s)len(s) ss的字符数
s.startswith("hel")s.startswith("hel") s starts with the substring s是否以子字符串"hel""hel"开头
s.endswith("lo")s.endswith("lo") s ends with the substring s是否以子字符串"lo""lo"结尾
"{} plus {} is {}".format(3,1,4)"{} plus {} is {}".format(3,1,4) 3, 31, and 1 ,和4 inserted4插入
s.replace("e","z")s.replace("e","z") s with all occurances of s返回一个新字符串,所有出现的"e" replaced with "e"替换为"z""z"
s.strip()s.strip() s with any whitespace at the start and end of the string removeds的新字符串,并在字符串的开头和结尾删除了空格
s.split(" ")s.split(" ") s into a list of strings, separating on the character s拆分为字符串列表,以字符" " and return that list" "分隔并返回该列表

数值类型和数学运算 (Numeric Types and Mathematical Operations)

i = int("5")i = int("5") "5" to the integer "5"转换为整数5 and assign the result to 5并将结果分配给ii
f = float("2.5")f = float("2.5") "2.5" to the float value "2.5"转换为浮点值2.5 and assign the result to 2.5 ,并将结果分配给ff
5 + 55 + 5 Addition 加成
5 - 55 - 5 Subtraction 减法
10 / 210 / 2 Division
5 * 25 * 2 Multiplication 乘法
3 ** 23 ** 2 3 to the power of 3提高到2 (or )2 (或)的幂
27 ** (1/3)27 ** (1/3) 3rd root of 27 (或)的第27 (or )3
x += 1x += 1 x + 1 to x + 1的值分配给xx
x -= 1x -= 1 x - 1 to x - 1的值分配给xx

清单 (Lists)

l = [100, 21, 88, 3]l = [100, 21, 88, 3] 100, 10021, 2188, and 88 ,和3 to the variable 3至可变ll
l = list()l = list() ll
l[0]l[0] ll
l[-1]l[-1] ll
l[1:3]l[1:3] ll的第二个和第三个值的切片(列表)
len(l)len(l) ll的元素数
sum(l)sum(l) ll的值之和
min(l)min(l) ll返回最小值
max(l)max(l) ll返回最大值
l.append(16)l.append(16) 16 to the end of 16附加到ll的末尾
l.sort()l.sort() l in ascending orderl中的项目进行排序
" ".join(["A", "B", "C", "D"])" ".join(["A", "B", "C", "D"]) ["A", "B", "C", "D"] into the string ["A", "B", "C", "D"]转换为字符串"A B C D""ABCD"

辞典 (Dictionaries)

d = {"CA": "Canada", "GB": "Great Britain", "IN": "India"}d = {"CA": "Canada", "GB": "Great Britain", "IN": "India"} "CA", "CA""GB", and "GB""IN" and corresponding values of of "IN"以及"Canada", "Canada""Great Britain", and "Great Britain""India""India"对应值创建字典
d["GB"]d["GB"] d that has the key d中返回具有键"GB""GB"
d.get("AU","Sorry")d.get("AU","Sorry") d that has the key d具有关键"AU", or the string "AU"或字符串"Sorry" if the key "Sorry"如果键"AU" is not found in "AU"中找不到dd
d.keys()d.keys() dd返回键列表
d.values()d.values() dd的值列表
d.items()d.items() (key, value) pairs from d返回d(key, value)对的列表

模块和功能 (Modules and Functions)

The body of a function is defined through indentation

函数的主体通过缩进定义

import randomimport random randomrandom导入模块
from random import randomfrom random import random random from the module random从模块randomrandom
calculate with two required and two optional named arguments which calculates and returns a result.calculate ,该参数计算并返回结果。
addition(3,5,factor=10)addition(3,5,factor=10) addition function with the values 33 and 5以及命名参数5 and the named argument 10运行10addition函数

布尔比较 (Boolean Comparisons)

x == 5x == 5 x is equal to x是否等于55
x != 5x != 5 x is not equal to x是否等于55
x > 5x > 5 x is greater than x是否大于55
x < 5x < 5 x is less than x是否小于55
x >= 5x >= 5 x is greater than or equal to x是否大于或等于55
x <= 5x <= 5 x is less than or equal to x是否小于或等于55
x == 5 or name == "alfred"x == 5 or name == "alfred" x is equal to x是否等于5 or 5name is equal to name等于"alfred""alfred"
x == 5 and name == "alfred"x == 5 and name == "alfred" x is equal to x是否等于5 and 5并且name is equal to name是否等于"alfred""alfred"
5 in l5 in l 5 exists in the list l是否存在值l5
"GB" in d"GB" in d "GB" exists in the keys for d的键中是否存在值d"GB"

语句和循环 (Statements and Loops)

The body of if statements and loops are defined through indentation

if语句和循环的主体是通过缩进定义的

if x > 5:
    print("{} is greater than five".format(x))
elif x < 0:
    print("{} is negative".format(x))
else:
    print("{} is between zero and five".format(x))
if x > 5:
    print("{} is greater than five".format(x))
elif x < 0:
    print("{} is negative".format(x))
else:
    print("{} is between zero and five".format(x))
x and run the code body based on the valuex的值并基于该值运行代码主体
l, running the code in the body of the loop with each iteration.l每个值,并在每次迭代时在循环体内运行代码。
while x < 10:
    x += 1
while x < 10:
    x += 1
x is no longer less than x的值不再小于1010

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

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

python 桌面备忘录

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值