![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
KongX_B
个人主页www.kongxiangbo.com
展开
-
Python-Numpy(1)Array数组
import numpyworld_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter=",")print(type(world_alcohol))#The numpy.array() function can take a list or list of lists as input. When we input a list, w原创 2017-08-11 08:10:04 · 1178 阅读 · 0 评论 -
Python-Matplotlib(2)打造一个完整的折线图
import pandas as pdimport matplotlib.pyplot as pltunrate = pd.read_csv('unrate.csv')unrate['DATE'] = pd.to_datetime(unrate['DATE'])first_twelve = unrate[0:12]plt.plot(first_twelve['DATE'], first_tw原创 2017-08-13 11:07:46 · 4597 阅读 · 0 评论 -
Python-Matplotlib(3) 条形图实战
import pandas as pdreviews = pd.read_csv('fandango_scores.csv')cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']norm_reviews = reviews[col原创 2017-08-13 11:11:57 · 2443 阅读 · 0 评论 -
Python-Matplotlib(4) 直方图与四分图
import pandas as pdimport matplotlib.pyplot as pltreviews = pd.read_csv('fandango_scores.csv')cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue']norm_reviews原创 2017-08-13 11:16:46 · 5167 阅读 · 0 评论 -
Python-Matplotlib(4) 基于真实数据集的可视化分析
import pandas as pdimport matplotlib.pyplot as pltwomen_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')plt.plot(women_degrees['Year'], women_degrees['Biology'])plt.show()#100-women_原创 2017-08-13 11:22:00 · 1980 阅读 · 0 评论 -
Python-Matplotlib(5) 可视化图表细节
#Colorimport pandas as pdimport matplotlib.pyplot as pltwomen_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')major_cats = ['Biology', 'Computer Science', 'Engineering', 'Math and St原创 2017-08-13 11:26:17 · 540 阅读 · 0 评论 -
常用浏览器内核驱动下载地址
Firefox: (geckodriver.exe) https://github.com/mozilla/geckodriver/releasesIE: (IEDriverServer) http://selenium-release.storage.googleapis.com/index.html 下载版本需要与selenium版本一致 conda list即可看到Chrom: ht原创 2017-08-24 19:43:03 · 1081 阅读 · 0 评论 -
Sublime搭建Python环境
使用sublime text配置Python开发环境 安装Package Control: Preferences->install Package Control 快捷键ctrl+shift+p 输入install手动:https://packagecontrol.io/installation#st3 先安装 sidebarEnhancements 侧边栏安装下列插件: S原创 2017-08-24 22:07:08 · 450 阅读 · 0 评论 -
[转载]Python爬取豆瓣影评并生成词云图代码
# -*- coding:utf-8 -*-'''抓取豆瓣电影某部电影的评论这里以《我不是潘金莲为例》网址链接:https://movie.douban.com/subject/26630781/comments为了抓取全部评论需要先进行登录'''from selenium import webdriverimport timeimport codecsimport jieba转载 2017-08-24 23:08:33 · 5382 阅读 · 0 评论 -
Python决策树可视化Graphviz下载地址
下载地址:http://www.graphviz.org/pub/graphviz/stable/windows/原创 2017-09-05 12:16:20 · 715 阅读 · 0 评论 -
Python词云图
新模块介绍:Pickle 如果希望透明地存储 Python 对象,而不丢失其身份和类型等信息,则需要某种形式的对象序列化:它是一个将任意复杂的对象转成对象的文本或二进制表示的过程。同样,必须能够将对象经过序列化后的形式恢复到原有的对象。在 Python 中,这种序列化过程称为 pickle,可以将对象 pickle 成字符串、磁盘上的文件或者任何类似于文件的对象,也可以将这些字符串、文件或任何类似原创 2017-08-24 15:19:24 · 2293 阅读 · 0 评论 -
决策树算法详解(2)
Python决策树原生版参考#encoding:utf-8import mathdef createDataSet(): #训练数据集 dataSet=[['young','myope','no','reduced','no lenses'], ['young','myope','no','normal','soft'],转载 2017-09-12 20:18:25 · 425 阅读 · 0 评论 -
常见排序算法
冒泡排序冒泡排序是最简单的排序之一了,其大体思想就是通过与相邻元素的比较和交换来把小的数交换到最前面。这个过程类似于水泡向上升一样,因此而得名。举个栗子,对5,3,8,6,4这个无序序列进行冒泡排序。首先从后向前冒泡,4和6比较,把4交换到前面,序列变成5,3,8,4,6。同理4和8交换,变成5,3,4,8,6,3和4无需交换。5和3交换,变成3,5,4,8,6,3.这样一次冒泡就完了,把最小的数3原创 2017-11-07 17:45:30 · 296 阅读 · 0 评论 -
Python常用函数与技巧总结(二)
列表生成式 a=[i for i in range(0,5)] print(a)[0,1,2,3,4]filter(function,iterable) 过滤器list(filter(lambda x:x%2,range(10)))维度shape shape[0] 横向几行 shape[1] 纵向几列 [[5 10 15] [20 25 30]]a=np.array([5,原创 2017-11-05 20:24:50 · 252 阅读 · 0 评论 -
Python常用函数与技巧总结(三)
主方法:if__name__='__main__':构造方法:def __init__(self): self.xxx=yyy区分公有和私有 公有的正常写 name=’jack’ 私有的前面加两个下划线 __age=12方法: 对象方法具有self参数 def method(self): 类方法使用修饰器@classmethod,具有cls参数 def原创 2017-11-05 22:18:03 · 279 阅读 · 0 评论 -
Python-Matplotlib(1)画折线图
import pandas as pdunrate = pd.read_csv('unrate.csv')unrate['DATE'] = pd.to_datetime(unrate['DATE'])print(unrate.head(12))import matplotlib.pyplot as plt#%matplotlib inline#Using the different pyp原创 2017-08-13 11:01:36 · 1030 阅读 · 0 评论 -
Python-Pandas(6)数据索引变换
import pandas as pd#will return a new DataFrame that is indexed by the values in the specified column #and will drop that column from the DataFrame#without the FILM column dropped fandango = pd.read原创 2017-08-13 10:07:25 · 544 阅读 · 0 评论 -
Python-Pandas(5)核心数据结构Series详解
#Series (collection of values)#DataFrame (collection of Series objects)#Panel (collection of DataFrame objects)#A Series object can hold many data types, including#float - for representing float val原创 2017-08-13 09:55:18 · 334 阅读 · 0 评论 -
Python基础总结(1)
全干货:语句不加分号 定义变量:days=365 输出: print days print “xxx” 2.7 print(“xxx”)3.0返回类型:type()返回类型 如 type(days)强制转换类型:str(xx) int(xx)运算符:+ - * / 次方:** a的2次方原创 2017-08-10 21:34:45 · 221 阅读 · 0 评论 -
Python基础总结(2)
字典: 列表表示含义:students=["Tom","Jim","Sue","Ann"]scores=[70,80,85,75]indexes=[0,1,2,3]name="Sue"score=0#找名字是苏的成绩是多少for i in indexes: if students[i]=="Sue": score=scores[i]print score就是类原创 2017-08-10 21:44:45 · 232 阅读 · 0 评论 -
Python基础总结(3)
文件操作: 读txt文本f=open("aaa.txt","r")g=f.read()print gf.close()写文件f=open("tttt.txt","w")f.write('12646')f.write('\n')f.write('5416')f.close()CSV文件:test_data=[]f=open("unrate.csv","r")data=f.read(原创 2017-08-10 22:25:55 · 216 阅读 · 0 评论 -
Python基础总结(4)
元组:戴上枷锁的列表tuple1=(1,2,3,4,5,6,7,8)更新元素方法temp=('aaa','vvv','ccc','ddd')temp=temp[:2]+('hehe',)+temp[2:]print "{0}.{1}.{2}".format("www","superkingdom","cn")print "{a}.{b}.{c}".format(a="www",b="superk原创 2017-08-10 22:50:38 · 167 阅读 · 0 评论 -
Python基础总结(5)
递归阶乘算法:def jc(a): if a==1: return 1 else: return a*jc(a-1)斐波那契数列 1 1 2 3 5 8 13 21 34 55 89 144 |1, 当n=1 Fn|1, 当n=2 |F(n-1)+F(n-2) 当n>2两种算法: 一:迭原创 2017-08-10 22:58:53 · 265 阅读 · 0 评论 -
Numpy知识巩固
import numpy as np#1:8*8棋盘矩阵,其中1、3、5、7行&&0、2、4、6列的元素置为1 1 ,3,5,7列&&0,2,4,6行也是1z = np.zeros((8,8),dtype=int)z[1::2,::2] = 1z[::2,1::2] = 1print z#2:min()、max()函数z = np.random.random((10,10))zmi原创 2017-08-12 12:43:11 · 1238 阅读 · 0 评论 -
Python-Numpy(2)Array数组操作
import numpy#it will compare the second value to each element in the vector# If the values are equal, the Python interpreter returns True; otherwise, it returns Falsevector = numpy.array([5, 10, 15,原创 2017-08-12 11:22:29 · 445 阅读 · 0 评论 -
Python-Numpy(3)矩阵基本操作
import numpy as npa = np.arange(15).reshape(3, 5)aa.shape#the number of axes (dimensions) of the arraya.ndim#维度a.dtype.name#the total number of elements of the arraya.sizenp.zeros ((3,4)) np.ones(原创 2017-08-12 11:34:53 · 991 阅读 · 0 评论 -
Python-Numpy(5)排序与索引
import numpy as np#data = np.sin(np.arange(20)).reshape(5,4)#print data#ind = data.argmax(axis=0)#print ind#data_max = data[ind, xrange(data.shape[1])]#print data_maxall(data_max == data.max(axi原创 2017-08-12 12:07:19 · 536 阅读 · 0 评论 -
Python-Numpy(4)常用函数
import numpy as npB = np.arange(3)print B#print np.exp(B)print np.sqrt(B)#Return the floor of the inputa = np.floor(10*np.random.random((3,4)))print a#a.shape## flatten the array#print a.ravel(原创 2017-08-12 11:54:30 · 591 阅读 · 0 评论 -
Python-Pandas(1)数据读取与显示,数据样本行列选取
import pandasfood_info = pandas.read_csv("food_info.csv")#print(type(food_info))print food_info.dtypes#first_rows = food_info.head()#print first_rows#print(food_info.head(3))#print food_info.colu原创 2017-08-12 14:25:18 · 12687 阅读 · 0 评论 -
Python-Pandas(2)数值计算与排序
import pandasfood_info = pandas.read_csv("food_info.csv")col_names = food_info.columns.tolist()print(col_names)print(food_info.head(3))#print food_info["Iron_(mg)"]#div_1000 = food_info["Iron_(mg)原创 2017-08-12 14:38:27 · 486 阅读 · 0 评论 -
Python-Pandas(3)数据预处理
import pandas as pdimport numpy as nptitanic_survival = pd.read_csv("titanic_train.csv")titanic_survival.head()#The Pandas library uses NaN, which stands for "not a number", to indicate a missing va原创 2017-08-13 09:19:52 · 418 阅读 · 0 评论 -
Python-Pandas(4)自定义函数方法
#specifying axis=1 or axis='columns' will drop any columns that have null valuesdrop_na_columns = titanic_survival.dropna(axis=1)new_titanic_survival = titanic_survival.dropna(axis=0,subset=["Age", "原创 2017-08-13 09:39:17 · 2424 阅读 · 0 评论 -
机器学习算法python实现
github:https://github.com/lawlite19/MachineLearning_Python#转载 2017-11-21 16:12:06 · 310 阅读 · 0 评论