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基础备忘单的内容

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数据科学速查表

python数据科学速查表_Python数据科学速查表:中级相关推荐

  1. python数据科学指南是什么_Python数据科学实践 | Spyder入门

    Spyder入门 01 Spyder--Python编程的"热带雨林" Spyder是一个用于科学计算的使用Python编程语言的集成开发环境(IDE).它结合了综合开发工具的高级 ...

  2. python制作股票图表怎么看_Python 数据可视化实战:使用 PyQt5 和 Echarts 打造股票数据看板...

    在一篇论文中,最吸引审稿人目光的莫过于枯燥的文字间精美的图表 在一份项目路演 ppt 中,酷炫的财务报表往往是打动投资人的最后一剂强心剂 作为数据分析最后也是最直接的一环,数据可视化的重要性不言而喻 ...

  3. python数据清理的实践总结_python 数据的清理行为实例详解

    python 数据的清理行为实例详解 数据清洗主要是指填充缺失数据,消除噪声数据等操作,主要还是通过分析"脏数据"产生的原因和存在形式,利用现有的数据挖掘手段去清洗"脏数 ...

  4. python折线图怎么添加数值_Python数据可视化:如何创建曲线图

    一图胜千言,使用Python的matplotlib库,可以快速创建高质量的图形. 用matplotlib生成基本图形非常简单,只需要几行代码,但要创建复杂的图表,需要调用更多的命令和反复试验,这要求用 ...

  5. python作中国地图背景气泡图_Python数据可视化:香港地图、房价可视化,绘制气泡图...

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于DataCharm ,作者宁海涛 前言 今天的推文教程使用geopandas进行空间 ...

  6. python panda 库箱线图_Python数据可视化:箱线图多种库画法

    概念 箱线图通过数据的四分位数来展示数据的分布情况.例如:数据的中心位置,数据间的离散程度,是否有异常值等. 把数据从小到大进行排列并等分成四份,第一分位数(Q1),第二分位数(Q2)和第三分位数(Q ...

  7. 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 ...

  8. python 统计组合用什么库_Python数据科学,用这些库就够了

    为了方便学习,本文列出的20个Python库将按领域进行分类,有些你可能并不熟悉,但是真的能提高你的模型算法实现效率,多一点尝试,多一些努力! ▌核心库和统计数据 1. NumPy (Commits: ...

  9. python亿级mysql数据库导出_Python实现将MySQL数据库表中的数据导出生成csv格式文件的方法...

    本文实例讲述了python实现将MySQL数据库表中的数据导出生成csv格式文件的方法.分享给大家供大家参考,具体如下: #!/usr/bin/env python # -*- coding:utf- ...

最新文章

  1. 个php反序列化漏洞,PHP反序列化漏洞学习(一)
  2. 同一个字符串hash值相同吗_图说:为什么Java中的字符串被定义为不可变的
  3. 将matpoltlib绘制好的图片从内存中取出
  4. 如何显示在线人数和所在位置
  5. @Async in Spring--转
  6. 不同时间段的欢迎语言
  7. 在alv list小计之后输出分割线
  8. SAP Business One助力洛德集团实现巨大商业价值
  9. 【读书札记】《怦然心动——情感化交互设计指南》
  10. java递归方法分析
  11. webpack4.0关闭开发环境的代码压缩UglifyJsPlugin
  12. 西数、希捷、DIY移动硬盘详细拆解,暴力解析
  13. 六 集成电路IP核技术行业研究分析——结论与启示
  14. 计算机保研er去清华计算法学怎么样?
  15. Flexbox在button/fieldset/legend中(比如safair)失效问题
  16. HECATE G2耳机麦克风问题解决
  17. 【C++】算法STL库
  18. ChatGPT 类大语言模型为什么会带来“神奇”的涌现能力?
  19. MySQL数据库基本管理
  20. Lab1实验过程及心得体会

热门文章

  1. 基于单片机的存钱罐系统设计(#0465)
  2. ajax 泛微oa表单js_泛微oa流程表单二次开发新人注意事项,
  3. 两个非常使用的工具仿站小工具7.0以及排版页面的工具
  4. MAC OS 命令行删除分区方法
  5. 邮件群发平台_海外疫情持续严重影响外贸市场,U-Mail邮件群发应对出招
  6. Grin:这个世界真的需要电子现金吗?
  7. Java原码、反码、补码转换
  8. 公路可视化景观设计解决方案
  9. 零基础想学好编程!C语言最难啃的 3 块硬骨头,你全吃透了吗?
  10. TeraCloud网盘挂载