python
大白羊的进阶之路
这个作者很懒,什么都没留下…
展开
-
pandas 缺失值与空值处理
1.相关函数df.dropna()df.fillna()df.isnull()df.isna()2.相关概念空值:在pandas中的空值是""缺失值:在dataframe中为nan或者naT(缺失时间),在series中为none或者nan即可3.函数具体解释DataFrame.dropna(axis=0, how='any', thresh=None, subset...转载 2018-08-14 10:10:04 · 983 阅读 · 0 评论 -
Python:在Python中 输出不重复的随机数
关键在于使用集合setimport randomh =set()while(len(h)<10): h.add(random.randint(10,100)) print(h)原创 2019-01-23 19:36:59 · 3158 阅读 · 0 评论 -
python: python求各种距离公式
一. scipy.spatial 模块的介绍在scipy.spatial中最重要的模块应该就是距离计算模块distance了。from scipy import spatial距离计算矩阵距离计算函数矩阵参数每行代表一个观测值,计算结果就是每行之间的metric距离。Distance matrix computation from a collection of raw obse...原创 2019-01-23 20:12:10 · 6784 阅读 · 1 评论 -
Python: 输入、输出
一、输出在程序中输出就是打印信息,python中通过print函数打印变量、常量、表达式、函数的结果,将结果显示在控制台,方便开发人员查看,以及调试程序示例如下:print('hello, world')print(300)print(100 + 200)print('100 + 200 =', 100 + 200)1.1格式化输出<1>格式化操作的目...转载 2019-01-08 22:13:14 · 271 阅读 · 0 评论 -
python: 求两个list 的交集,并集,差集
#!/usr/bin/env python#coding:utf-8'''Created on 2016年6月9日@author: lei.wang'''def diff(listA,listB): #求交集的两种方式 retA = [i for i in listA if i in listB] retB = list(set(listA).inters...转载 2019-01-09 14:44:53 · 480 阅读 · 0 评论 -
python:找出列表list中的重复元素
问题:一个列表中可能含有重复元素,使用set()可以实现列表的去重处理,但是无法知道哪些元素是重复的,下面的函数用于找出哪些元素重复了,以及重复的次数。【问题解决】from collections import Counter #引入Countera = [29,36,57,12,79,43,23,56,28,11,14,15,16,37,24,35,17,24,33,15,3...转载 2019-01-21 10:15:38 · 15283 阅读 · 0 评论 -
Python异常处理 -跳过异常继续执行
当循环中出现异常时,如何跳过循环中的异常继续执行,下面是一种可行的方法:import pandas as pddates=range(20161010,20161114)pieces=[]for date in dates: try: data=pd.read_csv('A_stock/overview-push-%d/stock overview.csv' %d...原创 2019-01-15 17:47:17 · 4620 阅读 · 0 评论 -
python中根据元素获得索引
1. 获取DataFrame的值的索引(1)可以用DataFrame的条件索引,即令df_sub=df[conditions],然后再获取df_sub的index属性即可如:random_fcd[random_fcd['time1']=='2.77'].index(2)对于某一个列(series类型的数据),可以先转化为list类型,然后利用list.index(values)方法获取...原创 2019-01-21 15:10:40 · 3214 阅读 · 0 评论 -
Python: 统计元素的个数
1. list.count(value)可返回value在list中的个数2.DataFrame.count()返回每行或每列的值的个数,除去空值(默认是行) DataFrame.count(axis =0) 或 DataFrame.count(axis =1) ...原创 2019-01-21 20:50:23 · 9157 阅读 · 0 评论 -
API(1): API中的数据类型, JSON 与 XML
API的大部分数据都是JSON或XML格式JSON ——JavaScriptobjectnotation ,JavaScript对象标记;xml代表可延伸标记语言。上面的数据很不自然,JSON对于展现和读取具有复杂结构的数据特别有用。JSON构建在两个关键结构上:1.JSON 对象:键值对2.JSON 数组:可以作为键值对中的值...原创 2019-04-25 22:27:57 · 679 阅读 · 0 评论 -
Python 字符串操作(截取/替换/查找/分割)
Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾。# 例1:字符串截取str = '12345678'print str[0:1]>> 1 # 输出str位置0开始到位置1以前的字符print str[1:6] >> 23456 # 输出str位置...原创 2019-01-06 22:57:33 · 562 阅读 · 0 评论 -
【python】numpy之random库简单的随机数据生成.rand()、.randint()、.randn()、.random()等(一)
原文链接: https://blog.csdn.net/brucewong0516/article/details/79011562转载 2018-11-14 00:41:30 · 317 阅读 · 0 评论 -
pandas删除指定行
【原文地址】https://blog.csdn.net/htbeker/article/details/79645651在处理pandas的DataFrame中,如果想像excel那样筛选,只要其中的某一行或者几行,可以使用isin()方法来实现,只需要将需要的行值以列表方式传入即可,还可传入字典,进行指定筛选。但是如果我们只想要所有内容中不包含特定行的内容,却并没有一个isnotin()...转载 2018-08-14 10:29:20 · 14371 阅读 · 1 评论 -
pandas.DataFrame中删除包涵特定字符串所在的行
【原文地址】https://blog.csdn.net/htbeker/article/details/79645651你在使用pandas处理DataFrame中是否遇到过如下这类问题?我们需要删除某一列所有元素中含有固定字符元素所在的行,比如下面的例子:...转载 2018-08-14 11:32:37 · 3851 阅读 · 0 评论 -
Python动态生成变量
用Python循环创建多个变量, 如创建 a1= 、a2= 、a3= 、a4= 、a5= 或 self.a1= 、self.a2= 、 self.a3=一. 可以通过python的内置函数locals 来完成locals是python的内置函数,他可以以字典的方式去访问局部和全局变量。python里面用名字空间记录着变量,就像javascript的win...转载 2018-09-04 16:25:27 · 773 阅读 · 0 评论 -
dataframe 取行、列 ;及其条件选择
dataframe 取列有两种方法: df.列名 或 df['列名'] ; 同时通过,df['列名1',‘列名2' ,。。。。] 可以选择多列。dataframe取行 和列: 通过loc类和iloc类 可以选择dataframe数据的多行和多列。 其...原创 2018-09-03 16:18:58 · 18038 阅读 · 1 评论 -
pandas求两个表格不相交的集合
首先先造两个DataFrame来做示例。import pandas as pd a0={"number":range(10),"letter":["a","a","b","b","c","f","f","e","h","w"]} a=pd.DataFram转载 2018-10-01 19:29:47 · 3622 阅读 · 0 评论 -
python生成随机数列表
一. 最直接的方式:用numpy.random模块来生成随机数组1、np.random.rand 用于生成[0.0, 1.0)之间的随机浮点数, 当没有参数时,返回一个随机浮点数,当有一个参数时,返回该参数长度大小的一维随机浮点数数组,参数建议是整数型,因为未来版本的numpy可能不支持非整形参数。import numpy as np>>> np.random.rand(...转载 2018-10-12 11:13:31 · 17252 阅读 · 0 评论 -
Pandas绘图(一):
转载自:https://blog.csdn.net/weixin_38168620/article/details/79797050约定:%matplotlib inline import pandas as pd import numpy as np import matplotlib.pyplot as plt 图的用途+pandas绘图...转载 2018-10-14 16:33:57 · 679 阅读 · 0 评论 -
(python中模块包的安装)安装anaconda特定版本的模块包
可以通过Anaconda Navigator 和 Pycharm两种途径安装 python中所需要的特定版本的模块包. 如: pandas 0.18.1同时也可通过上述方法删除模块包原创 2018-10-24 00:11:41 · 1485 阅读 · 0 评论 -
Anaconda3 x64位spyder和anaconda-navigator 不能正常启动
Anaconda3 x64位spyder和anaconda-navigator 不能正常启动在官网下载Anaconda3 后navigator无法打开,但是anaconda prompt 可以运行,对于navigator运行问题的解决办法: 分析下问题,anaconda的命令行可以打开,说明核心模块安装正确,后来找了好多办法,发现应该是UI(就是界面的插件的问题)1.先用cmd,输入命令c...转载 2018-10-24 01:34:29 · 1435 阅读 · 0 评论 -
Python:删除字符串中的 \ xa0
\xa0 is actually non-breaking space in Latin1 (ISO 8859-1), also chr(160). You should replace it with a space.string = string.replace(u'\xa0', u' ')When .encode('utf-8'), it will encode the uni...转载 2019-04-24 22:41:49 · 808 阅读 · 0 评论