随笔分类 -  Python数据科学

摘要:假设一个data中其某列值是显示工作单位属性的,为了方便算法计算,需要将这些属性转换成数值替换。 通过pd.series.unique()确认工作单位属性的个数 利于pandas方法转换 使作anywhere即可返回到值的索引。 将需要str类型的所有列全部转换 实现批量替换 第二种,利于sciki 阅读全文
posted @ 2020-10-12 11:13 hisweetyGirl 阅读(520) 评论(0) 推荐(0) 编辑
摘要:训练需要一段时间,出现下图字样,则代表训练完成。 注意[2,4]为数据中不存在的数值,进行预测. 阅读全文
posted @ 2020-08-04 15:54 hisweetyGirl 阅读(488) 评论(0) 推荐(1) 编辑
摘要:![](https://img2020.cnblogs.com/blog/1561536/202008/1561536-20200804152032713-603104877.png) ![](https://img2020.cnblogs.com/blog/1561536/202008/1561536-20200804152255345-57683144.png) ![](https://img 阅读全文
posted @ 2020-08-04 15:23 hisweetyGirl 阅读(341) 评论(0) 推荐(0) 编辑
摘要:第一步:读取三个表数据(用户表、评分表、电影表) mnames=['MovieID','Title','Genres'] user_data = pd.read_table(r".\datas\movielens-1m\users.dat", sep='::', header=None, names 阅读全文
posted @ 2020-08-01 17:57 hisweetyGirl 阅读(724) 评论(0) 推荐(0) 编辑
摘要:详见:https://www.cnblogs.com/Yanjy-OnlyOne/p/11195621.html 阅读全文
posted @ 2020-07-23 21:17 hisweetyGirl 阅读(170) 评论(0) 推荐(0) 编辑
摘要:#时间戳格式改为YYYY-mm-DD hh:MM:ss df['pdate']=pd.to_datetime(df['Timestamp'],unit='s') #从日期中快速取出月份 df_group=df.groupby([df["pdate"].dt.month,"Rating"])["Use 阅读全文
posted @ 2020-07-23 20:52 hisweetyGirl 阅读(986) 评论(0) 推荐(0) 编辑
摘要:上图是获取2018年每个月温度最高的2天数据。 另一种解题思路 要得到销售排名前3位的城市,先进行排序。 详细见https://www.sohu.com/a/344992003_165070 阅读全文
posted @ 2020-07-23 20:15 hisweetyGirl 阅读(1167) 评论(0) 推荐(0) 编辑
摘要:参考此文章:https://www.jianshu.com/p/e76861ed1815 写得很详细 map仅能传一下参数 map传入一个字典或一个函数都可。 apply可以传多个参数 apply注意asix值,asix=0,以列计算(按行扫数据),asix=1,以行计算(按列扫数据) applym 阅读全文
posted @ 2020-07-23 20:00 hisweetyGirl 阅读(295) 评论(0) 推荐(0) 编辑
摘要:同样以股票数据为例 Series单层索引 ser=stocks.grougby('公司').['收盘'].mean() 返回以公司为维度作为索引的平均值。(ser值的含义:A公司的股票收盘平均值,B公司的股票收盘平均值,...X公司的股票收盘平均值) Series的分层索引Mulitindex se 阅读全文
posted @ 2020-07-23 19:48 hisweetyGirl 阅读(354) 评论(0) 推荐(0) 编辑
摘要:分组统计在实际应用中是非常多的。比如:对不同地区的销售量的统计,不同班级的分数统计,同一月份的统计等。比如查询每个月最高气温。 先通过分组groapby方法查出每个月的聚合数据,而且再利于agg进行max计算。 group_data=df.groupby('month').agg({'bWendy' 阅读全文
posted @ 2020-07-23 19:32 hisweetyGirl 阅读(388) 评论(0) 推荐(0) 编辑
摘要:以天气为例 用agg传入一个字典,多个对比参数。比如天气的最大值,最小值,均值做比较。 阅读全文
posted @ 2020-07-21 21:23 hisweetyGirl 阅读(725) 评论(0) 推荐(0) 编辑
摘要:df.append(df2,ignore_index=False),按行添加 阅读全文
posted @ 2020-07-21 20:02 hisweetyGirl 阅读(133) 评论(0) 推荐(0) 编辑
摘要:Pandas的Merge相当于sql的join,将不同的表关联在一个表 #读取电影数据,sep为分割符 df_ratings=pd.read_csv(r'...\datas\movielens-1m\ratings.dat',sep='',engine='python',names='UserIDM 阅读全文
posted @ 2020-07-21 19:41 hisweetyGirl 阅读(195) 评论(0) 推荐(0) 编辑
摘要:`#读取目标excel表,忽略前面2行 df=pd.read_excel(r'F:\人工智能_优学\Pandas-learn-code\pandas-learn-code\datas\student_excel\student_excel.xlsx',skiprows=2) #去掉所有为NaN的列, 阅读全文
posted @ 2020-07-20 20:26 hisweetyGirl 阅读(599) 评论(0) 推荐(0) 编辑
摘要:1.汇总类统计 2.唯一去重和按值计数 3.相关系统和协方差 阅读全文
posted @ 2020-07-20 20:00 hisweetyGirl 阅读(123) 评论(0) 推荐(0) 编辑
摘要:按数值、列表、区间、条件、函数五种方法。 Pandas查询数据的几种方法 1.df.loc(),根据行、列的标签值查询(推荐使用) 2.df.iloc(),根据行、列的数值查询(不推荐使用) 3.df.where()方法 4.df.query()方法 重点 Pandas使用df.loc查询数据的方法 阅读全文
posted @ 2020-07-20 19:09 hisweetyGirl 阅读(9530) 评论(0) 推荐(0) 编辑
摘要:一、创建pandas可识别的一维数据和二维数据、多维数据 pd.Series(list/dict) pd.DataFrame(list/dict,index,column) #传入array二维数组,index行索引,column列索引 直接读取csv、数据库数据、txt pd.date_range 阅读全文
posted @ 2020-07-14 11:12 hisweetyGirl 阅读(795) 评论(0) 推荐(0) 编辑
摘要:numpy是用于处理矩阵运算非常好的工具。执行效率高,因为其底层是用的是C语句 #使用numpy,需要将数据转换成numpy能识别的矩阵格式。 基本用法: numpy.array(object, dtype = None, copy = True, order = None, subok = Fal 阅读全文
posted @ 2020-07-10 20:24 hisweetyGirl 阅读(845) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示