在Dataquest中学习Data Scientist方向的知识要点整理笔记。
Step1:Introduction to Python
- 打开文件
f = open("crime_rates.csv","r")
g = f.read()
- 分割list
sample = "john,plastic,joe"
split_list = sample.split(",")
- string中符号替换
text = "Howdy,my,name"
text = text.replace(",", "")
- Function
def clean_text(string_value,clean = False):#clean默认为False,可通过将实例中相应参数设为Ture来实现函数功能。
if clean:
cleaned_value = string_value.replace(",", "")
return(cleaned_value)
sentence = "Howdy,james,bond!"
sentence = clean_text(sentence,Ture)
- String大写变小写
words = "Michael JACKSON Thriller"
lower_words = words.lower()
- Model
利用csv中的.reader功能读取csv文件
import csv
f = open(&