Python學習,從安裝,到簡單應用
前言
Python作為膠水語言在web開發,數據分析,網絡爬蟲等方向有著廣泛的應用
一、Python入門
相關基礎語法直接使用相關測試代碼
Python編譯器版本使用3以后,安裝參考其他教程,此處不展開。
主要介紹Python一些基礎語法,如:字符串,字典,元組,列表使用,方法(函數),循環,類
測試代碼:
import statistics
import requests
print("hello world")
print((2**3))val_test = "calulate success"print(val_test.upper())
print(val_test.isupper())
print(val_test.islower())
# 制表符 換行符
print("country:\n\t CHN \n\t USA")#列表
annimals = ["tiger","dog","puma"]
print(annimals)
print(annimals[0].title())
# del annimals[0]
new_annimals = annimals.pop(1 )
print(new_annimals)
#for 迭代
for animal in annimals:print(animal+" is bargining")
#函數
def dsfunc(point="AAA"):a=1b=2c=a+bprint("hello world"+str(c)+point)return cprint(dsfunc("DMAIC"))
#元組 + 字典
dict_car = {("tom","NewYork"):"Spider",("White","NewMexico"): "Cooker"}
print(dict_car)
dict_car[("White","NewMexico")]="Cancer"
print(dict_car)#數學計算引入包 statistics
median_data = statistics.median([2,3,5,8,99,8,7,55])
print("中位數: ",median_data)
#多行字符串
contentDS = """
1. 基礎語法
2. 網絡編程與文件操作
3. 其他補充
4. 爬蟲
5. <其他>"""
print("contentDS: ",contentDS)pascal = -5
if pascal>0:print("pascal>0")
elif pascal==0:print("pascal=0")
else:print("pascal < 0")
效果如下:
?hello world
8
CALULATE SUCCESS
False
True
country:
?? ? CHN?
?? ? USA
['tiger', 'dog', 'puma']
Tiger
dog
tiger is bargining
puma is bargining
hello world3DMAIC
3
{('tom', 'NewYork'): 'Spider', ('White', 'NewMexico'): 'Cooker'}
{('tom', 'NewYork'): 'Spider', ('White', 'NewMexico'): 'Cancer'}
中位數: ?7.5
contentDS: ?
1. 基礎語法
2. 網絡編程與文件操作
3. 其他補充
4. 爬蟲
5. <其他>
? ? ? ??
pascal < 0
Python中,沒有使用花括號定義代碼域,使用冒號代表以下為類似代碼域內容?定義與使用類 :
class Dog:def __init__(self,name,age):self.name=nameself.age=agedef bargin(self):self.name="bargin Dog"print(self.name + " is barging")mydog = Dog("white",18)mydog.bargin()
二、應用
1.爬蟲
簡單實現代碼如下(示例):
import requests
# 此處隱藏掉了對應的地址
url ="********"
response = requests.get(url)
response.encoding = 'utf-8'
codeVideo = response.status_code
# open("F:\\temp\\BBB.mp4","wb").write(response.content)
其中URL地址被隱藏,在對應網頁檢查網頁或者按下F12后通過網絡(NetWork)使用媒體(media)中的頭信息獲取,如圖:
需要注意的是,一些主流視頻平臺都有反爬機制,這個案例僅做參考。?
2.數據分析
數據分析基礎入門:
對業務深入理解;對數據分析不止停留在工具上,要深度融合業務達到深入思考后的關鍵信息用于決策;多思考,多實踐培養數據敏感性,對業務提供合理發展建議;業務/技術/算法 都需要一定基礎。
對待臨時需求,需要追根尋底,建立模型
專題分析最能體現分析師業務價值,要形成自己的方法論建立模型,才能看到本質避免過多臨時取數工作。
?需求解讀過程要貫穿整個數據分析過程,邏輯樹建立,SQL提數要盡可能避免過多臨時要求。
總結
提示:這里對文章進行總結:
例如:以上就是今天要講的內容,本文僅僅簡單介紹了pandas的使用,而pandas提供了大量能使我們快速便捷地處理數據的函數和方法。