Python第三方库
LaoChen_ZeroonE
这个作者很懒,什么都没留下…
展开
-
pandas 过滤数据
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChen"""df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD')) Out[9]: A B C D 2017-04-01 0.522241 0.495106 -0.268194原创 2021-04-13 21:18:27 · 321 阅读 · 0 评论 -
pandas 删除nan
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChen"""创建DataFrame样例数据>>> import pandas as pd>>> import numpy as np>>> data = pd.DataFrame({'a': [1, 2, 4, np.nan,7, 9], 'b': ['a', 'b', np.nan, np.nan, 'd', 'e'原创 2021-04-13 21:17:04 · 431 阅读 · 0 评论 -
pandas数据排序
Series的排序:Series.sort_values(ascending=True, inplace=Flase)参数说明:ascending:默认为True升序排列,为Flase降序排序inplace: 是否修改原始的SeriesDataFrame的排序DataFrame.sort_values(by, ascending=True, inplace=Flase )参数说明:by: 字符串或者List<字符串>,单列排序或者多列排序ascending:bool或者.原创 2021-03-10 00:23:44 · 534 阅读 · 0 评论 -
python 排列组合
python 排列组合#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChenimport itertools#组合a = itertools.permutations(['a','b','c'], 2)print(type(a))print(list(a))#排列a = itertools.combinations(['a','b','c'], 2)print(type(a))print(list(a原创 2021-03-01 23:02:46 · 78 阅读 · 0 评论 -
python 判断nan值
python 判断nan值#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChen"""None 和 nantype(None)-----------Nonetypetype(Nan)-------------float判断nan这里出了7个判断的方法,但实际有效的只有3个,还有半有效的~后四个方法则是只有np.nan可以判断自己的类型,其他三种没办法自己判断自己。也就是说:np.nan is np.nan是原创 2021-03-01 23:01:27 · 1397 阅读 · 0 评论 -
pandas画图
pandas画各种图表#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChenimport pandas as pdimport numpy as np"""设置字体和显示中文Pandas在绘图时,会显示中文为方块,主要原因有二: matplotlib 字体问题,seaborn 字体问题。没有中文字体,所以我们只要手动添加中文字体的名称就可以了,不过并不是添加我们熟悉的“宋体”或“黑体”这类的名称,而是要添加字体原创 2021-03-01 22:58:23 · 176 阅读 · 0 评论 -
python list元素统计
python list元素统计方法#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChendata = [1,1,1,2,2,2,3,3,1,4,2,2,3,2,3,1,6,7,8]#1from collections import Counterresult = Counter(data)print("result:",result)#2data_dict = {}for key in data:原创 2021-03-01 22:56:38 · 969 阅读 · 0 评论 -
pandas apple传参
pandas apple传参三种方式#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChenimport pandas as pdimport datetime #用来计算日期差的包def dataInterval(data1,data2): d1 = datetime.datetime.strptime(data1, '%Y-%m-%d') d2 = datetime.datetime.strpti原创 2021-03-01 22:54:36 · 577 阅读 · 0 评论 -
pandas-df拼接
merge(left, right, how=‘inner’, on=None, left_on=None, right_on=None,left_index=False, right_index=False, sort=True,suffixes=(’_x’, ‘_y’), copy=True, indicator=False)#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : LaoChen"""merge(left, ri原创 2021-02-23 23:37:46 · 495 阅读 · 1 评论 -
python安装第三方包超时HTTPSConnectionPool(host=‘files.pythonhosted.org‘, port=443): Read timed out
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed outpip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.T原创 2020-08-17 23:20:21 · 5281 阅读 · 0 评论 -
DataFrame-diff函数、重置索引、替换
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2020/5/26 23:07# @Author : LaoChenimport pandas as pddict3 = {'a': [6, 4, 3, 5, 2, 1], 'b': ['a', 's', 'd', 'f', 'g', 'h'], 'c': [1, 4, 9, 16, 25, 36]}df = pd.DataFrame(dict3)原创 2020-05-28 22:17:34 · 1011 阅读 · 0 评论 -
matplotlib-画图参数-日期做x轴
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2020/5/25 22:02# @Author : LaoChenimport matplotlib.pyplot as pltimport datetimedef day_list(): days = [1,2,3,4,5,6,7,8,9] base_date = datetime.datetime(2020,1,1) date_list = []原创 2020-05-25 22:32:42 · 1184 阅读 · 0 评论 -
python-list、dataframe转换、遍历
List转换为DataframePandas中将列表转换成为数据框有两种方法:第一种是两个不同列表转换成一个数据框,第二种是一个包含不同子列表的列表转换成为数据框。#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2020/5/25 21:36# @Author : LaoChen#方法一import pandas as pda = ['a1','a2','a3','a4'] #列表ab = [0,1,0,1] #列表b原创 2020-05-25 21:40:45 · 6330 阅读 · 0 评论 -
pySpark.Dataframe转Pandas
pySpark中将数据toPandas(),但是toPandas()也会运行慢 运行内存不足等问题。在网上找到一种方法,比自带的toPandas()更快捷。import pandas as pddef _map_to_pandas(rdds): """ Needs to be here due to pickling issues """ return [pd.DataFrame(list(rdds))]def to_Pandas(df, n_partitions=None):原创 2020-05-11 21:49:26 · 3922 阅读 · 0 评论 -
NetworkX进阶
NetworkX进阶算法近似和启发式优化问题的图性质和启发式函数的近似。这些函数可以通过 from networkx.algorithms import approximation连通性节点连接的快速近似all_pairs_node_connectivity (g) [, nbunch, cutoff] )计算所有节点对之间的节点连接local_node_conne...原创 2020-01-14 10:32:43 · 2156 阅读 · 0 评论 -
NetworkX
NetworkXnetworkx是一个python包,用于创建、操作和研究复杂网络的结构、动态和功能。• 研究社会、生物和基础设施网络结构和动态的工具;• 一种适用于多种应用的标准编程接口和图形实现;• 为协作性、多学科项目提供快速发展环境;• 与现有的数值算法和C、C++和FORTRAN代码的接口;• 能够轻松处理大型非标准数据集。使用NetworkX,可以以标准和非标准数据格式加...原创 2020-01-13 19:27:54 · 756 阅读 · 0 评论