《利用Python进行数据分析》 笔记
记录了本人在学习《利用Python进行数据分析》一书过程中遇到的零零散散的知识
ljt爱喝老猪阿茶
这个作者很懒,什么都没留下…
展开
-
Python读取文件错误问题 字符编码(转载)
https://blog.csdn.net/qq_18888869/article/details/82625343?utm_source=distribute.pc_relevant.none-task转载 2020-02-19 20:04:32 · 146 阅读 · 0 评论 -
numpy中axis参数理解
对axis的理解在我理解看来,numpy中参数axis代表的就是维度。即通过.shape函数输出的元素有几个,axis 最大 就是几,即这个数组最大的维度。同时注意,在numpy中 rank 代表的是数组的维度而不是秩,区别于线代的rank在numpy中,rank和axis的最大值是一个意思import numpy as npimport pandas as pdrng = np.ra...原创 2020-02-14 16:10:44 · 825 阅读 · 0 评论 -
Python 文件读取
**1.open()和close()**在读取文件内容前需先打开文件,并且在结束后关闭文件代码:f = open('hallo.txt','r')print(f)f.close()print(f.read()) #read()函数将返回文件内容输出:<_io.TextIOWrapper name='hallo.txt' mode='r' encoding='cp936...原创 2020-02-12 17:57:10 · 226 阅读 · 0 评论 -
collections模块中的counter类
http://www.pythoner.com/205.html转载 2020-02-18 21:56:42 · 127 阅读 · 0 评论 -
pandas iloc和loc的区别
简单来说,iloc()和loc()区别就在于前者是通过索引名来索引,后者通过索引值索引同时要注意,当一个DataFrame的索引是默认状态时,二者没有什么区别,因为索引值和索引名都是一样的来看下面几个例子先看看iloc()的df = pd.DataFrame(np.arange(0,45,3).reshape(5,3), index = ['a','b',...原创 2020-02-17 14:36:50 · 216 阅读 · 0 评论 -
pandas unstack()和stack()函数
.unstack()和.stack()首先创建一个多级的DataFramedata = pd.DataFrame(np.arange(6).reshape((2, 3)), index=pd.Index(['Ohio','Colorado'], name='state'), columns=pd.Index([...原创 2020-02-15 22:09:33 · 1083 阅读 · 0 评论 -
pandas combine_first()函数
.combine_first()以例子说明df1 = pd.DataFrame([np.nan, 1, 2, np.nan,3])df2 = pd.DataFrame([1, 2, 3, np.nan, np.nan])print(df1)print('————')print(df2)print('————')print(df1.combine_first(df2)) #用d...原创 2020-02-15 20:35:44 · 1067 阅读 · 0 评论 -
Python collections模块 用defaultdict / setdefault 函数 和counter类型 统计元素出现的次数
现在我们假如有一个列表,需要统计其中每种元素的个数,我们可以这样写lis1 = ['a','b','c','a','c','a','a','b','c']result = {}for i in lis1: if i in result: result[i] += 1 else: result[i] = 1print(result)out:...原创 2020-02-18 21:01:40 · 137 阅读 · 0 评论
分享