例如:第一章 Python 基础知识
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
# operators
# 基础运算子
print(1+1)
print("1+1")
print(2*5)
print("2*5")
print("2"*5)
print(1234/123)
print(1234%123)
print(123^3)
print(123**3)
# Condictions
# 基礎運算子練習 條件判斷
a = 1
b = 2
print(b == 2.1)
print(a == 1)
print(b == 2.1 or a == 1)
print(b == 2.1 and a == 1)
# If Condiction
# 練習if
age = 2
print("你家狗狗的年龄")
if age < 0:
print("業障重!")
elif age == 1:
print(" 相當於 14 歲的人。")
elif age == 2:
print(" 相當於 22 歲的人。")
elif age > 2:
human = 22 + (age -2)*5
print(" 相當於{}歲的人。: ".format(human))
# For Loop
# 練習For Loop
for loop_number in range(10):
print(loop_number)
String_List = ["hello world 1234", "hello world 2234","hello world 2 ","hello world 3 "]
for loop_string in String_List:
print(loop_string)
for loop_string in String_List[0]:
print(loop_string)
list_close_price = [20, 21, 22, 19, 25]
find_highest_price = 0
for loop_number in list_close_price:
if loop_number > find_highest_price:
find_highest_price = loop_number
print(loop_number)
print(loop_number)
# 練習函式
def Im_function():
list_close_price = [20, 21, 22, 19, 25,18,17,26,10,8]
find_highest_price = 0
for loop_number in list_close_price:
if loop_number > find_highest_price:
find_highest_price = loop_number
print("hight")
print(find_highest_price)
print("day close")
print(loop_number)
# While Loop
# 練習While Loop
print("While loop")
n = 5
while n > 0:
n = n - 1
print(n)
print('循環結束。')
print("Continue")
n = 5
while n > 0:
n = n - 1
if n == 2:
continue
print(n)
print('循環結束。')
print("Break")
n = 5
while n > 0:
n = n - 1
if n == 2:
break
print(n)
print('循環結束。')
#安装pyautogui库
pip install pyautogui
import pyautogui
# 獲取當下點座標
print(pyautogui.position())
# 在螢幕上查詢匹配與檔案相同的區域--每個區域畫素都要相同 左,頂,寬,高
pyautogui.locateOnScreen('submit.png')
# 獲取匹配影象中心點座標
pyautogui.center(pyautogui.locateOnScreen('submit.png'))
up_down = 0
left_right = 0
pyautogui.moveTo(up_down,left_right,duration=1)
pyautogui.moveRel(up_down,left_right,duration=1)
pyautogui.dragTo(up_down, left_right, duration=1, button='left')
pyautogui.dragRel(up_down,left_right,duration=1)
pyautogui.click(up_down,left_right)
# 寫一隻簡單掛網程式
# 輸入需要反應的螢幕圖像名稱
picture_list = ["submit1.png","submit2.png","submit3.png","submit4.png","submit5.png"]
# 輸入需要拖曳至之螢幕圖像名稱
picture_drag_into = "drag_to_this_image.png"
# 跑無限迴圈掛網
while Ture :
# 遍歷所有需要反應的螢幕圖像
for dealing_picture in picture_list :
#取得該反應的螢幕圖像座標
position_up_down , position_left_right = pyautogui.center(pyautogui.locateOnScreen(dealing_picture))
#將滑鼠移動至該螢幕圖像座標
pyautogui.moveTo(position_up_down,position_left_right,duration=5)
#點擊滑鼠
pyautogui.click()
#取得需要拖曳至之螢幕圖像座標
drag_position_up_down , drag_position_left_right = pyautogui.center(pyautogui.locateOnScreen(picture_drag_into))
#拖曳該反應的螢幕圖像座標點 至 需要拖曳至之螢幕圖像座標
pyautogui.dragTo(drag_position_up_down, drag_position_left_right, duration=5, button='left')
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
代码如下(示例):
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
代码如下(示例):
data = pd.read_csv(
'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())
该处使用的url网络请求的数据。
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。