- 博客(18)
- 收藏
- 关注
原创 文件处理函数(菜鸟教程)
输入input()open(filename, mode):r,b,w,a(不存在,会抛出异常)r以只读方式打开文件。文件的指针将会放在文件的开头,这是默认模式。如果文件不存在,抛出异常w以只写方式打开文件。如果文件存在会被覆盖。如果文件不存在,创建新文件a以追加方式打开文件。如果该文件已存在,文件指针将会放在文件的结尾。如果文件不存在,创建新文件进行写入r+以读写方式打开文件。文件的指针将会放在文件的开头。如果文件不存在,抛出异常w+以读写方
2020-05-17 11:41:21
319
原创 面向对象(基础知识笔记)
class、object如果希望属性是私有的,在给属性命名时可以用两个下划线作为开头属性@property包装器:方法伪装属性,不能有参数,必须实例化后调用,类不能调用与所定义的属性配合使用,防止属性被修改@属性名.setter@属性名.deleterslots: 限定自定义类型的对象只能绑定某些属性只对当前类的对象生效,对子类并不起任何作用。@staticmethod静态方法,调用:类名.静态方法不会隐式传递self被装饰函数可无参数,不能引
2020-05-17 11:32:56
244
原创 正则表达式和re库(菜鸟教程)
匹配:(pattern, string, flags=0)re.match()只匹配字符串的开始re.search():整个字符串检索和替换:re.sub()(pattern, repl, string, count=0, flags=0)编译正则表达式:re.compile(pattern[, flags])返回列表::re.findall(string[, pos[, endpos]])迭代器返回::re.finditer(pattern, string, flags=0
2020-05-17 11:27:17
1092
原创 urllib, XPath和lxml
HTTP协议HTTP:超文本传输协议,发布和接收HTTP页面的方法。端口80.HTTPS协议:HTTP加密版本,加入了SSL。端口443 请求过程: 输入url回车,发生请求。 服务器response 浏览器分析response,再次发送request,获取images,css,js等 下载成功后显示url详解:统一资源定位符组成:scheme://host:port/path/?query-str
2020-05-16 22:36:59
947
1
原创 scrapy
爬虫框架软件结构就功能组件集合,使用的模板。5+2结构 Engine:调度中心 Scheduler调度器:待爬取URL,去重 Downloader下载器:获取页面信息 Spiders:初始request,分析response并提取item,额外的Request Item Pipeline:处理数据,存储 Spider middlewares:处理spider的输入(response)和输出(item, requests),修改丢弃新增请求和响应
2020-05-16 22:28:31
586
1
原创 爬虫: requests, Beautiful Soup, 正则
requests库:请求robots.txt:爬虫排除标准Beautiful Soup:解析HTML页面re:正则表达式Scrapy框架IDEIDLE:自带SublimeText:专业Wing:调试功能,多人开发Visual Studio & PTVS, PyCharm数据分析,科学计算:Canop, AnacondaRequest库r = requests.request(url, params=None, **kwargs)Request——Response 1.
2020-05-16 22:26:22
644
1
原创 Jupyter 魔术命令(整理)
常用命令命令作用?说明%lsmagic显示全部%matplotlib inline图片嵌入窗口,而不单独显示(默认)%timeit, %timeit单行代码执行计时%%timeit多行计时%prun每个函数消耗时间%%writefile创建一个py文件,内容为cell里%run运行一个py文件%pwd查找当前目录%cd更改当前目录%cp复制文件%who列出所有变量,+类型可过滤%whos查
2020-05-16 22:21:45
2866
1
原创 Introduction to Data Visualization with Python(datacamp)
Customizing plotsPlotting multiple graphsimport matplotlib.pyplot as pltplt.plot(x, y1, 'red')plt.plot(x, y2, 'blue')plt.xlabel('x')plt.title('title')plt.show()# units between 0 and 1plt.axes([x_figure, y_figure, width, height])#subplot:nmk..
2020-05-16 22:19:11
533
原创 Cleaning Data in Python(datacamp)
拿到数据,先要了解数据:file.head()file.tail()file.shapefile.columnsfile.info()频数计算:file.col_name.value_counts(drapna=False)#orfile[col_name].value_counts(drapna=False)#计算特征数file.describe()数据可视化:#histogramfile.col_name.plot('hist')plt.show()# box p
2020-05-16 22:16:33
900
原创 importing Data in Python(datacamp)
Flat files"Flat"which means it has no structure for indexing and there are usually no structural relationships between the records.Flat File是一种包含没有相对关系结构的记录的文件。 这个类型通常用来描述文字处理、其他结构字符或标记被移除了的文本。一个flat file即可以是纯文本文件(plain text file),也可以是二进制文件(binary file..
2020-05-16 22:15:23
381
原创 Interactive Data Visualization with Bokeh(datacamp)
1.Basic plotting with Bokeh<1> what are Glyphs visual shapes : circles, squares, triangles ; recetangle, lines, wedges with properties attached to data : size, color, transparency, coordinates(x,y)from bokeh.io import output_file, showfrom bok
2020-05-16 22:13:56
354
原创 Manipulating DataFrames with pandas(datacamp)
Extracting and transforming data1索引 DataFramesiloc,即index locate 用index索引进行定位,loc,则可以使用column名和index名进行定位,df.loc[rowname,colname]df.iloc[num,num]df[colname] #Seriesdf[[colname]] #DataFrame#sample# Print the boolean equivalenceprint(election..
2020-05-16 22:12:29
591
原创 Merging DataFrames with pandas(datacamp)
Preparing data1.reading multiple data file#for loopdf = [pd.read_csv(file) for file in filenames]#grobfrom glob import globfilenames = glob('___') #包含通配符df = [pd.read_csv(file) for file in filenames]2.reindexing DataFrameindices: many index..
2020-05-16 22:11:04
411
原创 pandas Foundations(datacamp)
1.Data ingestion & inspection1.了解数据基础信息type(df)df.head()df.tail()df.info()df.valuesdf.column.dtypedf.shape2.创建DataFramedf=pd.DataFrame(...)#示例# Zip the 2 lists together into one list of (key,value) tuples: zippedzipped = list(zip(list_ke
2020-05-16 22:08:52
305
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅