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编程:入门课程,可以帮助您开始数据科学之旅。
Download a Printable PDF of this Cheat Sheet
下载此备忘单的可打印PDF
关键基础知识,打印和获得帮助 (Key Basics, Printing and Getting Help)
This cheat sheet assumes you are familiar with the content of our Python Basics Cheat Sheet
该备忘单假定您熟悉我们的Python基础备忘单的内容
s s
|
A Python string variable | Python字符串变量 |
i i
|
A Python integer variable | Python整数变量 |
f f
|
A Python float variable | Python浮点变量 |
l l
|
A Python list variable | Python列表变量 |
d d
|
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 中等于x x 的第一项
|
l.reverse() l.reverse()
|
l l 项目的顺序
|
l[1::2] l[1::2]
|
l , commencing from the l ,从开始1 st item1 日项目
|
l[-5:] l[-5:]
|
l l 中的最后5个项目
|
弦乐 (Strings)
s.lower() s.lower()
|
s s 的小写版本
|
|
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 的前s 5 字符
|
|
"fri" + "end" "fri" + "end"
|
"friend" "friend"
|
|
"end" in s "end" in s
|
True if the substring s 找到子字符串"end" is found in "end" 则返回s True
|
范围 (Range)
Range objects are useful for creating sequences of integers for looping.
范围对象对于创建整数序列进行循环很有用。
range(5) range(5)
|
0 to 0 到4 4 的序列
|
range(2000,2018) range(2000,2018)
|
2000 to 2000 到2017 2017 的序列
|
range(0,11,2) range(0,11,2)
|
0 to 0 到10 , with each item incrementing by 10 的序列,每一项增加2 2
|
range(0,-10,-1) range(0,-10,-1)
|
0 to 0 到-9 -9 的序列
|
list(range(5)) list(range(5))
|
0 to 0 到4 4 的列表
|
辞典 (Dictionaries)
max(d, key=d.get) max(d, key=d.get)
|
d d 最大值的键
|
min(d, key=d.get) min(d, key=d.get)
|
d d 最小值的键
|
套装 (Sets)
my_set = set(l) my_set = set(l)
|
set object containing the l unique values from 唯一值的l set 对象
|
|
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_set a in my_set
|
True if the value my_set 存在值a exists in a 则返回my_set True
|
常用表达 (Regular expressions)
import re import 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 对象,否则返回None None
|
|
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 0 到9 9 的值的平方的列表
|
[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.5 0.5
|
循环功能 (Functions for looping)
|
l , printing the index location of each item and its valuel ,打印每个项目的索引位置及其值
|
l_one and l_one 和l_two and print each valuel_two 并打印每个值
|
|
|
x is no longer less than x 的值不再小于10 10
|
约会时间 (Datetime)
import datetime as dt import datetime as dt
|
datetime moduledatetime 模块
|
now = dt.datetime.now() now = dt.datetime.now()
|
datetime object representing the current time to datetime 对象到now now
|
wks4 = dt.datetime.timedelta(weeks=4) wks4 = dt.datetime.timedelta(weeks=4)
|
timedelta object representing a timespan of 4 weeks to timedelta 对象分配给wks4 wks4
|
now - wks4 now - wks4
|
datetime object representing the time 4 weeks prior to datetime 对象表示时间前4周now now
|
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_2020 newyear_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 random import random
|
random modulerandom 模块
|
random.random() random.random()
|
0.0 and 0.0 和1.0 1.0 之间的随机浮点数
|
random.randint(0,10) random.randint(0,10)
|
0 and 0 到10 10 之间的随机整数
|
random.choice(l) random.choice(l)
|
l l
|
计数器 (Counter)
from collections import Counter from 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 l 到c c
|
c.most_common(3) c.most_common(3)
|
l l 最常见的3个项目
|
尝试/除外 (Try/Except)
Catch and deal with errors
捕捉并处理错误
|
l_ints l_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数据科学速查表
python数据科学速查表_Python数据科学速查表:中级相关推荐
- python数据科学指南是什么_Python数据科学实践 | Spyder入门
Spyder入门 01 Spyder--Python编程的"热带雨林" Spyder是一个用于科学计算的使用Python编程语言的集成开发环境(IDE).它结合了综合开发工具的高级 ...
- python制作股票图表怎么看_Python 数据可视化实战:使用 PyQt5 和 Echarts 打造股票数据看板...
在一篇论文中,最吸引审稿人目光的莫过于枯燥的文字间精美的图表 在一份项目路演 ppt 中,酷炫的财务报表往往是打动投资人的最后一剂强心剂 作为数据分析最后也是最直接的一环,数据可视化的重要性不言而喻 ...
- python数据清理的实践总结_python 数据的清理行为实例详解
python 数据的清理行为实例详解 数据清洗主要是指填充缺失数据,消除噪声数据等操作,主要还是通过分析"脏数据"产生的原因和存在形式,利用现有的数据挖掘手段去清洗"脏数 ...
- python折线图怎么添加数值_Python数据可视化:如何创建曲线图
一图胜千言,使用Python的matplotlib库,可以快速创建高质量的图形. 用matplotlib生成基本图形非常简单,只需要几行代码,但要创建复杂的图表,需要调用更多的命令和反复试验,这要求用 ...
- python作中国地图背景气泡图_Python数据可视化:香港地图、房价可视化,绘制气泡图...
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于DataCharm ,作者宁海涛 前言 今天的推文教程使用geopandas进行空间 ...
- python panda 库箱线图_Python数据可视化:箱线图多种库画法
概念 箱线图通过数据的四分位数来展示数据的分布情况.例如:数据的中心位置,数据间的离散程度,是否有异常值等. 把数据从小到大进行排列并等分成四份,第一分位数(Q1),第二分位数(Q2)和第三分位数(Q ...
- python for循环九九乘法表_Python中的九九乘法表(for循环)
用for循环写出的九九乘法表(包括函数的调用) #方向一 for i in range(1,10): for j in range(1,i+1): d = i * j print('%d*%d=%-2 ...
- python 统计组合用什么库_Python数据科学,用这些库就够了
为了方便学习,本文列出的20个Python库将按领域进行分类,有些你可能并不熟悉,但是真的能提高你的模型算法实现效率,多一点尝试,多一些努力! ▌核心库和统计数据 1. NumPy (Commits: ...
- python亿级mysql数据库导出_Python实现将MySQL数据库表中的数据导出生成csv格式文件的方法...
本文实例讲述了python实现将MySQL数据库表中的数据导出生成csv格式文件的方法.分享给大家供大家参考,具体如下: #!/usr/bin/env python # -*- coding:utf- ...
最新文章
- 个php反序列化漏洞,PHP反序列化漏洞学习(一)
- 同一个字符串hash值相同吗_图说:为什么Java中的字符串被定义为不可变的
- 将matpoltlib绘制好的图片从内存中取出
- 如何显示在线人数和所在位置
- @Async in Spring--转
- 不同时间段的欢迎语言
- 在alv list小计之后输出分割线
- SAP Business One助力洛德集团实现巨大商业价值
- 【读书札记】《怦然心动——情感化交互设计指南》
- java递归方法分析
- webpack4.0关闭开发环境的代码压缩UglifyJsPlugin
- 西数、希捷、DIY移动硬盘详细拆解,暴力解析
- 六 集成电路IP核技术行业研究分析——结论与启示
- 计算机保研er去清华计算法学怎么样?
- Flexbox在button/fieldset/legend中(比如safair)失效问题
- HECATE G2耳机麦克风问题解决
- 【C++】算法STL库
- ChatGPT 类大语言模型为什么会带来“神奇”的涌现能力?
- MySQL数据库基本管理
- Lab1实验过程及心得体会