文章目录

  • 前言
  • 一、pandas是什么?
  • 二、使用步骤
    • 1.引入库
    • 2.读入数据
  • 总结
  • 6 小时 Python 入门
    • 一、安装 Python
    • 二、安装代码编辑器 PyCharm
    • 三、HelloWorld
    • 四、Python 语法
    • 五、入门练习题
      • 1.打印 10 个 *
      • 2.打印价格
      • 3.描述医院病人的信息
      • 4.接收用户输入,打印问候信息
      • 5.打印年龄
      • 6.字符串打印
      • 7.格式化字符串
      • 8.字符串方法使用
      • 9.算术运算符
      • 10.引入数学模块
      • 11.条件语句的使用
      • 12.打印天气
      • 13.打印名字是否符合要求
      • 14.判断体重
      • 15.打印 1 - 5
      • 16.猜数(秘密号码)
      • 17.Car game
      • 18.for 循环使用
      • 19.计算价格总量
      • 20.嵌套循环
      • 21.List
      • 22.List 中找最大值
      • 23.访问矩阵中的各项
      • 24.数组中常用函数调用
      • 25.元组
      • 26.使用字典
      • 27.输出表情符号
      • 28.函数
      • 29.异常处理
      • 30.注释
      • 31.类的使用
      • 32.继承的使用
      • 33.调用模块使用
      • 34.从整个模块中导入特定的函数
      • 35.从包中导入特定的函数
      • 36.生成随机值
      • 37.寻找目录路径
      • 38.表格中读取信息
      • 39.CSV 文件导入数据
        • 整体输出数据
        • 获取数据集的形状
        • 分段输出数据
        • 获取值
        • 清洁数据
      • 40.决策树
        • 测量数据精确度
    • 六、参考资料
  • 第一章 Python 基础
    • 1.1 环境准备
      • 1.1.1 Python 安装
      • 1.1.2 安装代码编辑器 PyCharm
      • 1.1.3 安装 Jupyter notebook
    • 1.2 第一个 Python 程序
      • 1.2.1 HelloWorld
      • 1.2.2 输入和输出
        • ① 输出
        • ② 输入
      • 1.2.3 小结
      • 1.2.4 实例 1:温度转换
    • 1.3 Python 基础
      • 1.3.1 数据类型
        • ① 整数
        • ② 浮点数
        • ③ 字符串
        • ④ 布尔值
        • ⑤ 空值
        • ⑥ 列表
          • Ⅰ 可变的有序列表 list [ ]
          • Ⅱ 不可变有序列表 - 元组 tuple ( )
        • ⑦ 字典
          • Ⅰ dict(key - value) { }
          • Ⅱ set(key,且 key 不可重复) ([ \])
      • 1.3.2 再议不可变对象
      • 1.3.3 变量与常量
        • ① 变量
        • ② 常量
      • 1.3.4 字符串和编码
        • ① 字符串编码问题
        • ② 字符串详解
        • ③ 格式化
        • ④ format()
      • 1.3.5 条件判断
      • 1.3.6 循环
        • ① for ... in
        • ② while 循环
        • ③ break
        • ④ continue
    • 1.4 参考资料
  • 第二章 函数
    • 2.1 调用函数
      • 2.1.1 内置函数
      • 2.1.2 数据类型转换
    • 2.2 定义函数
      • 2.2.1 def 定义
      • 2.2.2 空函数
      • 2.2.3 参数检查
      • 2.2.4 返回多个值
    • 2.3 函数的参数
      • 2.3.1 位置参数
      • 2.3.2 默认参数
      • 2.3.3 可变参数
      • 2.3.4 关键字参数
      • 2.3.5 命名关键字参数
      • 2.3.6 参数组合
    • 2.4 递归函数
    • 2.5 参考资料
  • 第三章 高级特性
    • 3.1 切片
      • 3.1.1 list 切片
      • 3.1.2 tuple 切片
      • 3.1.3 str 切片
    • 3.2 迭代
    • 3.3 列表生成式
      • 3.3.1 if ... else
    • 3.4 生成器
    • 3.5 迭代器
    • 3.6 参考资料
  • 第四章 函数式编程
    • 4.1 什么是函数式编程
      • 4.1.1 定义
      • 4.1.2 特点
        • ① 函数是"第一等公民"
        • ② 只用"表达式",不用"语句"
        • ③ 没有"副作用"
        • ④ 不修改状态
        • ⑤ 引用透明
      • 4.1.3 好处
        • ① 代码简洁,开发快速
        • ② 接近自然语言,易于理解
        • ③ 更方便的代码管理
        • ④ 易于"并发编程"
        • ⑤ 代码的热升级
    • 4.2 高阶函数
      • 4.2.1 map/reduce
        • ① map
        • ② reduce
      • 4.2.2 filter
        • ① 用 filter 求素数
      • 4.2.3 sorted
        • ① 排序算法
    • 4.3 返回函数
      • 4.3.1 函数作为返回值
      • 4.3.2 闭包
    • 4.4 匿名函数
    • 4.5 装饰器
    • 4.6 偏函数
    • 4.7 参考资料
  • 第五章 模块
    • 5.1 使用模块
      • 5.1.1 作用域
    • 5.2 安装第三方模块
      • 5.2.1 安装常用模块
      • 5.2.2 模块搜索路径
    • 5.3 标准库的使用
      • 5.3.1 turtle 库
        • ① 实例:Python 蟒蛇绘制
        • ② turtle 库基本介绍
        • ③ turtle 绘图窗体布局
        • ④ turtle 空间坐标体系
        • ⑤ turtle 角度坐标体系
        • ⑥ RGB 色彩体系
        • ⑦ turtle 程序语法元素分析
    • 5.4 参考资料
  • 第六章 面向对象编程
    • 6.1 类和实例
      • 6.1.1 数据封装
    • 6.2 访问限制
    • 6.3 继承和多态
      • 6.3.1 静态语言 vs 动态语言
    • 6.4 获取对象信息
      • 6.4.1 使用 type()
      • 6.4.2 使用 isinstance()
      • 6.4.3 使用 dir()
    • 6.5 实例属性和类属性
    • 6.6 参考资料
  • 第七章 面向对象高级编程
    • 7.1 使用 `__slots__`
    • 7.2 使用 @property
    • 7.3 多重继承
      • 7.3.1 MixIn
    • 7.4 定制类
      • 7.4.1 `__str__`
      • 7.4.2 `__iter__`
      • 7.4.3 `__getitem__`
      • 7.4.4 `__getattr__`
      • 7.4.5 `__call__`
    • 7.5 使用枚举类
      • 7.5.1 Enum
    • 7.6 使用元类
      • 7.6.1 type()
      • 7.6.2 metaclass
    • 7.7 参考资料
  • 第八章 错误、调试和测试
    • 8.1 错误处理
      • 8.1.1 try
      • 8.1.2 调用栈
      • 8.1.3 记录错误
      • 8.1.4 抛出错误
    • 8.2 调试
      • 8.2.1 print()
      • 8.2.2 断言
      • 8.2.3 logging
      • 8.2.4 pdb
      • 8.2.5 pdb.set_trace()
      • 8.2.6 IDE
    • 8.3 单元测试
      • 8.3.1 运行单元测试
      • 8.3.2 setUp 与 tearDown
    • 8.4 文档测试
    • 8.5 参考资料
  • 第九章 IO 编程
    • 9.1 文件读写
      • 9.1.1 读文件
      • 9.1.2 file-like Object
      • 9.1.3 二进制文件
      • 9.1.4 字符编码
      • 9.1.5 写文件
    • 9.2 StringIO 和 BytesIO
      • 9.2.1 StringIO
      • 9.2.2 BytesIO
    • 9.3 操作文件和目录
      • 9.3.1 环境变量
      • 9.3.2 操作文件和目录
    • 9.4 序列化
      • 9.4.1 JSON
      • 9.4.2 JSON 进阶
    • 9.5 参考资料
  • 第十章 进程和线程
    • 10.1 多进程
      • 10.1.1 multiprocessing
      • 10.1.2 Pool
      • 10.1.3 子进程
      • 10.1.4 进程间通信
    • 10.2 多线程
      • 10.2.1 Lock
      • 10.2.2 多核 CPU
    • 10.3 ThreadLocal
    • 10.4 进程 vs. 线程
      • 10.4.1 线程切换
      • 10.4.2 计算密集型 vs. IO密集型
      • 10.4.3 异步 IO
    • 10.5 分布式进程
    • 10.6 参考资料

前言

提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。


提示:以下是本篇文章正文内容,下面案例可供参考

一、pandas是什么?

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

二、使用步骤

1.引入库

代码如下(示例):

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import  ssl
ssl._create_default_https_context = ssl._create_unverified_context

2.读入数据

代码如下(示例):

data = pd.read_csv('https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())

该处使用的url网络请求的数据。


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

6 小时 Python 入门

以下操作均在 Windows 环境下进行操作,先说明一下哈

一、安装 Python

1、官网下载 Python

进入官网(https://www.python.org),点击 Downloads,选择要下载的版本:

2、安装 Python

安装时注意下图勾选部分一定要勾选:

二、安装代码编辑器 PyCharm

1、官网下载 PyCharm

进入官网(https://www.jetbrains.com/pycharm),点击 Downloads,选择要下载的版本:

2、安装 PyCharm

设置安装路径之后,一直点 next 即可。

3、优化 PyCharm 使用

  • PyCharm 优化使用

三、HelloWorld

创建第一个项目 HelloWorld --> 创建文件 app.py --> 写入代码:

print("HelloWorld")

效果图:

四、Python 语法

看语法部分之前,推荐直接看下面入门练习题,潜移默化中对 Python 基本语法会有一定了解之后,再回来看这一部分,会更加熟悉 Python 的使用!

  • Python 语法使用要熟记于心

五、入门练习题

1.打印 10 个 *

使用到表达式

print('*' * 10)

2.打印价格

使用到变量

price = 10
print(price)

3.描述医院病人的信息

#!/usr/bin/env python3
# -*- coding: utf-8 -*-"""
@Time        : 2020/5/18
@Author      : WuGenQiang
@File        : hospital
@Description : 描述医院病人的信息
"""
full_name = 'John Smith'
age = 20
is_new = True

4.接收用户输入,打印问候信息

使用输入函数 input() 进行输入

name = input('what is your name?')
print('Hi ' + name)

测试:

5.打印年龄

使用到强制类型转换

birth_year = input('Birth year: ')
age = 2019 - int(birth_year)
print(age)

使用 type() 打印数据类型:

print(type(birth_year))

6.字符串打印

三种字符串表达形式

course_1 = 'Python for "Beginners"'
print(course_1)
course_2 = "Python is my 'love'"
print(course_2)
course_3 = '''
Hi John
welcome to python world!
'''
print(course_3)

效果呈现:

获取 course_1 的第一个索引值:

print(course_1[0])

获取 course_1 的最后一个索引值:

print(course_1[-1])

那么获取倒数第二个索引值呢:

print(course_1[-2])

返回索引为 0 - 2 的值:

print(course_1[0:3])

返回索引 0 以及 0 之后的所有字符:

print(course_1[0:])

返回索引小于 5 的所有字符:

print(course_1[:5])

返回所有字符:

print(course_1[:])

返回从第 2 位开始,不包括最后一位字符的字符串:

print(course_1[1:-1])

7.格式化字符串

first = 'WuGenQiang'
last = 'happy'
# 字符串拼接
message = first + ' [' + last + '] is a coder'
# 格式化字符串
msg = f'{first} [{last}] is a coder'
print(message)
print(msg)

8.字符串方法使用

(1)len() 函数:求字符串长度

course = 'Python for Beginners'
# 字符串长度
print(len(course))

(2)upper() 函数:转换成大写字母

# 转换成大写字母
print(course.upper())

(3)lower() 函数:转换成小写字母

# 转换成小写字母
print(course.lower())

(4)find() 函数

# 找字符返回第一个匹配的索引值
print(course.find('n'))

找不到返回 -1,并且区分大小写

(5)replace() 函数

# 替换字符
print(course.replace('Beginners', 'Absolute Beginners'))

(6)in 使用:产生布尔值 False or True

# 判断字符串是否在字符串里
print('Python' in course)

9.算术运算符

举例:

print(10 / 3)
print(10 % 3)
print(10 * 3)
# 10 的 3 次方
print(10 ** 3)x = 10
x = x + 3
x += 3
print(x)

思索下面 x 为多少:

x = 10 + 3 * 2 ** 2

答案是 22,因为取幂运算符是优先的,所以先算 2 的 2 次方

  • 取绝对值
print(abs(-2.9))

10.引入数学模块

import math
print(math.floor(2.9))

11.条件语句的使用

使用 if - elif - else

is_hot = False
is_cold = True
if is_hot:print("It's a hot day")
elif is_cold:print("It's a cold day")
else:print("It's a lovely day")
print("Enjoy your day")

当条件多个并且是 “and” 的关系时,使用:

has_high_income = True
has_good_credit = True
if has_good_credit and has_high_income:print("Eligible for loan")

若当条件多个并且是 “or” 的关系时,使用:

has_high_income = False
has_good_credit = True
if has_good_credit or has_high_income:print("Eligible for loan")

如何使用 “not”,看下面:(not 相当于取反)

has_good_credit = True
has_criminal_record = False
if has_good_credit and not has_criminal_record:print("Eligible for loan")

12.打印天气

使用比较运算符

temperature = 30
if temperature > 30:print("It's a hot day")
else:print("It's a cold day")

13.打印名字是否符合要求

使用比较运算符

name = "James"
if len(name) < 3:print("Name must be at least 3 character")
elif len(name) > 50:print("Name must be a maximum of 50 character")
else:print("Name looks good")

14.判断体重

weight = int(input('weight: '))
unit = input('(L)bs or (K)g: ')
if unit.upper() == "L":converted = weight * 0.45print(f"You are {converted} kilos")
else:converted = weight / 0.45print(f"You are {converted} pounds")

15.打印 1 - 5

使用到 while 循环语句或者 for 循环语句

i = 1
while i <= 5:print(i)i = i + 1
print("Done")

16.猜数(秘密号码)

secret_number = 9
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:guess = int(input('Guess: '))guess_count += 1if guess == secret_number:print('You won!')break
else:print('Sorry, you failed')

17.Car game

command = ""
started = Falsewhile True:command = input("> ").lower()if command == "start":if started:print("Car is already started!")else:started = Trueprint("Car started...")elif command == "stop":if not started:print("Car is already stopped!")else:started = Falseprint("Car stopped.")elif command == "help":print("""start - to start the carstop - to stop the carquit - to quit""")elif command == "quit":breakelse:print("Sorry, I don't understand that!")

18.for 循环使用

# 打印 Python
for item in 'Python':print(item)for item in ['Mosh', 'John', 'Sarah']:print(item)for item in [1, 2, 3, 4]:print(item)# 使用范围函数 range, range(10) 表示 0 - 9
for item in range(10):print(item)
# range(5, 10) 表示 5 - 9
for item in range(5, 10):print(item)
# range(5, 10, 2) 表示 5 - 9, 但是 step = 2
for item in range(5, 10, 2):print(item)

19.计算价格总量

使用到 for 循环

prices = [10, 20, 30]
total = 0
for price in prices:total += price
print(f"Total: {total}")

20.嵌套循环

for x in range(4):for y in range(3):print(f'({x}, {y})')

画个大大的 “F”

  • 方式一:
numbers = [5, 2, 5, 2, 2]
for x_count in numbers:print('x' * x_count)
  • 方式二:
numbers = [5, 2, 5, 2, 2]
for x_count in numbers:output = ''for count in range(x_count):output += 'x'print(output)

21.List

names = ['John', 'Bob', 'Mosh', 'Sarah', 'Mary']
print(names)
print(names[:])
print(names[2:])
# 输出第一个索引值
print(names[0])
# 输出最后一个索引值
print(names[-1])

22.List 中找最大值

numbers = [3, 6, 2, 8, 4, 10]
max = numbers[0]
for number in numbers:if number > max:max = number
print(max)

23.访问矩阵中的各项

matrix = [[1, 2, 3],[4, 5, 6],[7, 8, 9]
]
matrix[0][1] = 20
print(matrix[0][1])
for row in matrix:for item in row:print(item)

24.数组中常用函数调用

numbers = [5, 2, 1, 7, 4]
# 排序(升序)
numbers.sort()
# 逆序
numbers.reverse()
print(numbers)
# 复制拷贝
numbers2 = numbers.copy()
print(numbers2)
# 移除 1
numbers.remove(1)
# 清空
numbers.clear()
# 末尾加入 20
numbers.append(20)
# 在特定位置插入 12
numbers.insert(0, 12)
# 末尾删除
numbers.pop()
# 返回 5 的索引地址
print(numbers.index(12))
print(numbers)
# 输出 50 是否在 numbers 中
print(50 in numbers)
# 输出数字的数量
print(numbers.count(12))
  • 末尾加入数据
numbers = [2, 2, 4, 6, 3, 4, 6, 1]
uniques = []
for number in numbers:if number not in uniques:uniques.append(number)
print(uniques)

25.元组

numbers = (1, 2, 3)
print(numbers[0])

注意:

coordinates = (1, 2, 3)
# x = coordinates[0]
# y = coordinates[1]
# z = coordinates[2]
# 与上面相同结果
x, y, z = coordinates
print(x)

26.使用字典

  • 案例
customer = {"name": "John Smith","age": 30,"is_verified": True
}
customer["name"] = "Jack Smith"
print(customer["name"])
print(customer.get("name"))
print(customer.get("host", "123.12.1.1"))
  • 读号码
phone = input("Phone: ")
digits_mapping = {"1": "One","2": "Two","3": "Three","4": "Four","5": "Five"
}
output = ""
for ch in phone:output += digits_mapping.get(ch, "!") + " "
print(output)

27.输出表情符号

message = input("> ")
words = message.split(' ')
# 调用表情符号
emojis = {":)": "												

6 小时 Python 入门相关推荐

  1. python编程自学_Python编程自学:一小时python入门教程

    python好学吗?python入门要多久?python编程自学行吗?做为没有python编程基础的初学者肯定有各种各样的疑问!以下为python学习网整理的一位台湾小姐姐写的"一小时pyt ...

  2. python入门教程收藏_python入门教程:超详细保你1小时学会Python,快来收藏看看...

    简介:简介(转发文章+私信[Python]获取资料方式)1.Hello world安装完Python之后,打开IDLE(Python GUI) ,该程序是Python语言解释器,你写的语句能够立即运行 ...

  3. python入门教程收藏_python入门教程:超详细保你2小时学会Python,快来收藏看看...

    简介:(转发文章+私信[Python]获取资料方式)1.Hello world安装完Python之后,打开IDLE(Python GUI) ,该程序是Python语言解释器,你写的语句能够立即运行.我 ...

  4. 视频教程-8小时Python零基础轻松入门-Python

    订阅后:请点击此处观看视频课程 视频教程-8小时Python零基础轻松入门-Python 学习有效期:永久观看  学习时长: 525分钟  学习计划:9天 难度:低 「口碑讲师带队学习,让你的问题不过 ...

  5. Python教程笔记----6小时完全入门

    学习所看的视频来源于B站,授课老师:Mosh Hamedani老师 视频网址:python教程2019版 6小时完全入门 并且达到能开发网站的能力 目前最好的python教程 (含中文翻译)_哔哩哔哩 ...

  6. Python Mosh 学习笔记(6小时完全入门)

    Python Mosh 学习笔记 这两个博主写得都挺好的. 六小时极速入门 Python笔记 code with Mosh 02:01:45 2D Lists 02:05:11 My Complete ...

  7. 大数据技术之_23_Python核心基础学习_01_计算机基础知识 + Python 入门 (9.5小时)

    大数据技术之_23_Python核心基础学习_01 第一章 计算机基础知识 1.1 课程介绍 1.2 计算机是什么 1.3 计算机的组成 1.4 计算机的使用方式 1.5 windows 的命令行 1 ...

  8. 大数据技术之_23_Python核心基础学习_01_计算机基础知识 + Python 入门 (9.5小时)...

    第一章 计算机基础知识1.1 课程介绍1.2 计算机是什么1.3 计算机的组成1.4 计算机的使用方式1.5 windows 的命令行1.6 环境变量(environment variable)1.7 ...

  9. 编程语言python入门要电脑什么配置能带动-对于几乎是零基础的人,直接学 Python 编程合适吗?...

    在众多高大上的自学指导中,尝试做一股清流,把要讲清楚的都讲清楚,除了一堆资料之外,你能在学之前就有一个非常明显的结果倾向. 本文以<小白带你学Python>为内容方向,试图在繁杂的信息里, ...

最新文章

  1. AB1601继电器干扰问题
  2. Spring MVC 数据验证——validate注解方式
  3. cfile清空文件内容_编译-链接-加载 :ELF文件格式解析
  4. canopen和1939区别_CAN 和 CANopen的区别和联系
  5. JavaScriptSerializer类 对象序列化为JSON,JSON反序列化为对象
  6. 【国际专场】laravel多用户平台(SaaS, 如淘宝多用户商城)的搭建策略
  7. 【Java】基本语法训练题
  8. Android安全笔记-Intent和PendingIntent基本概念
  9. python执行一段代码_我发现了个 Python 黑魔法,执行任意代码都会自动念上一段 『平安经』...
  10. Spring Boot2整合Shiro(1):身份认证
  11. AI 应届博士生年薪八十万,贵吗?
  12. JAVA的MySQL字符串拼接_MySQL字符串拼接、截取
  13. Html5固定链接生成二维码的技巧
  14. Verilog学习笔记(7)Modelsim仿真_三角波发生器
  15. 用计算机弹琴琴谱,在电脑上弹钢琴的软件
  16. 子类继承父类,父类实现接口,子类中调用父类和接口的同名成员变量会出现歧义
  17. torch.manual_seed()及其作用
  18. Solidity语言编辑器REMIX指导大全
  19. FZU1901 Period II
  20. OBS点播电影电视剧添加场景

热门文章

  1. 进培训机构需要谨慎,在培训机构需要玩命,出培训机构需要坚持!
  2. CSS(二)——复合选择器、元素显示模式、背景、三大特性
  3. 订单号唯一ID顺序生成(一个轻量的实现)
  4. Shieldstar:一款改变世界的STG游戏!震撼发布!
  5. ERP业务逻辑-商品条码
  6. python操作xml
  7. 网页menu菜单自动生成器
  8. selenium窗口切换和关闭指定窗口
  9. 《Qt5+播放gif动图》
  10. 安卓软件前后端开发!2021最新Android知识体系总结,含泪整理面经