python基礎和程式設計庫

2021-08-28 03:52:24 字數 4602 閱讀 8342

二、python基礎面試題

三、程式設計庫

5.jieba [資料分析]

6.numpy & scipy [資料分析]

7. matplotlib[資料視覺化]

8. 正則(手機號例項)

四、實踐

r'\(~_~)/ \(~_~)/'
在多行字串前面新增r,把這個多行字串也變成乙個raw字串

r'''python is created by "guido".

it is free and easy to learn.

let's start learn python in imooc!'''

if age =

20if age >=18:

print

'your age is'

, age

print

'adult'

print

'end'

dict

d =

print

'adam:'

, d[

'adam'

]print

'lisa:'

, d[

'lisa'

]print

'bart:'

, d[

'bart'

]

單行注釋用#

多行注釋

「」"「」"

>>python基礎面試題<<

一次性獲得300多種用於科學和工程計算相關任務的python程式設計庫的支援

jupyter notebook基於網頁,python的ide

import time

print

(time.time())

time = time.localtime( time.time())

print

(time)

print

(time.tm_year)

"""1563803665.310865

time.struct_time(tm_year=2019, tm_mon=7, tm_mday=22, tm_hour=21, tm_min=54, tm_sec=25, tm_wday=0, tm_yday=203, tm_isdst=0)

2019

"""

封裝了大量經典以及最新的機器學習模型

針對於資料處理和分析的python工具包,實現了大量便於資料讀寫,清洗,填充及分析功能

import pandas as pd

# 兩個資料型別:series, dataframe

data_path =

"c:/users/admin/desktop/111.csv"

# 讀取檔案

defread_file

(data_path)

: datas = pd.read_csv(data_path, encoding=

"gbk"

) datas = datas.dropna(

)return datas

data = read_file(data_path)

print

(data)

# 獲取某一列文字 python 字典(dictionary) -->contents_agent 轉化成一整段

contents_agent = data[

"asr_agent_raw"

]contents = contents_agent.values.tolist(

)

import jieba

stopwords_file =

"d:/gitproject/smartlink-sqc/smartlink-sqc-wordle/python/dict/user_dict.txt"

defseg_word

(contents)

: contents = contents.values.tolist(

) jieba.load_userdict(stopwords_file)

segment =

for line in contents:

try:

segs = jieba.lcut(line)

for seg in segs:

iflen

(seg)

>

1and seg !=

'\r\n'

and \

u'\u4e00'

<= seg <= u'\u9fa5'

or \

u'\u0041'

<= seg <= u'\u005a'

or \

u'\u0061'

<= seg <= u'\u007a'

:except

:print

(line)

continue

words_df = pd.dataframe(

) stopwords = pd.read_csv(stopwords_file,

index_col=

false

, quoting=3,

sep=

"\t"

, names=

['stopwords'],

encoding=

'utf-8'

)# quoting=3全不引用

words_df = words_df[

~words_df.words.isin(stopwords.stopwords)

]return words_df

# 進行分詞

words_agent = seg_word(contents_agent)

print

(words_agent)

numpy最基礎的程式設計庫,提供一些高階的數**算機制和高效的向量和矩陣運算功能

scipy是子啊numpy的基礎上構建的,更為強大的科學計算包

import numpy as np

defword_freq

(words_df)

: words_stat = words_df.groupby(by=

['words'])

['words'

].agg(

) words_stat = words_stat.reset_index(

).sort_values(by=

["count"

], ascending=

false

)return words_stat

words_stat_agent = word_freq(words_agent)

# 列印詞頻較高的前10

print

(words_stat_agent.head(10)

)

繪圖工具包,柱狀圖標例

:# 取出中間四位

list

= phone[3:

7]# 加密

newphone = phone.replace(

list

,'****'

)return newphone

新聞推薦,電影推薦,朋友推薦,**推薦

代價函式:

python華為程式設計 程式設計 python基礎教程

python匯入模組的3種方式 超級詳細 在編寫完python模組之後,如果直接用 import 或 from.import 來匯入該模組,有時並不能正確地載入該模組。道理很簡單,僅通過我們提供的模組檔名,python 無法找到該模組檔案。程式設計其實並不難,就是用合適的語法告訴計算機,讓它幫助完成...

python 程式設計基礎

1.是單行注釋 2.內容 是多行注釋 1.乙個邏輯行可以占有多個物理行 用 分開 a this is life 當邏輯行使用括號時 包括圓括號 花括號 中括號 a a,b,c 2.乙個物理行建議只包含乙個邏輯行 多個邏輯行可以用 隔開 i 5 print i 1.盡量選擇乙個tab鍵或者4個空格鍵 ...

python程式設計基礎

date 2019 05 27 author sun 為了完成某種特定功能,以某種程式語言編寫的有序指令的集合。程式是指揮cpu工作的 工作手冊 計算機只能執行二進位制 程式語言一般類似英文,想要讓計算機理解你寫的程式,必須把程式 翻譯 成計算機能理解的二進位制 根據翻譯形式的不同,可以分為 解釋 ...