首页 文章 精选 留言 我的

精选列表

搜索[pandas],共942篇文章
优秀的个人博客,低调大师

pandas.Series.drop

Series. drop ( labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise' ) [source] Return new object with labels in requested axis removed. 去除指定轴向的数据。以下参数操作灵活,可以有不同路径完成同一目的 Parameters: labels: single label or list-like Index or column labels to drop. axis: int or axis name Whether to drop labels from the index (0 / ‘index’) or columns (1 / ‘columns’). index, columns: single label or list-like Alternative to specifyingaxis(labels,axis=1is equivalent tocolumns=labels). New in version 0.21.0. level: int or level name, default None For MultiIndex inplace: bool, default False If True, do operation inplace and return None. errors: {‘ignore’, ‘raise’}, default ‘raise’ If ‘ignore’, suppress error and existing labels are dropped. Returns: dropped: type of caller Notes Specifying bothlabelsandindexorcolumnswill raise a ValueError. Examples >>> df = pd.DataFrame(np.arange(12).reshape(3,4), columns=['A', 'B', 'C', 'D']) >>> df A B C D 0 0 1 2 3 1 4 5 6 7 2 8 9 10 11 Drop columns >>> df.drop(['B', 'C'], axis=1) A D 0 0 3 1 4 7 2 8 11 >>> df.drop(columns=['B', 'C']) A D 0 0 3 1 4 7 2 8 11 Drop a row by index >>> df.drop([0, 1]) A B C D 2 8 9 10 11

优秀的个人博客,低调大师

pandas和matplotlib和

高级数据操作工具,将数据存储为dataframe的数据结构。 注:将brics.csv文件放到D:/Documents下。 列的获取 添加咧 行的获取 元素的获取 数据可视化 1.折线图 2.散点图 3.直方图 4.轴的标签 5.标题 6.刻度 7.加入历史数据 Spark1.6.2.2.3 PCA 算法介绍: 主成分分析是一种统计学方法,它使用正交转换从一系列可能相关的变量中提取线性无关变量集,提取出的变量集中的元素称为主成分。使用PCA方法可以对变量集合进行降维。下面的示例将会展示如何将5维特征向量转换为3维主成分向量。 scala代码 importorg.apache.spark.ml.feature.PCA importorg.apache.spark.ml.linalg.Vectors valdata=Array( Vectors.sparse(5,Seq((1,1.0),(3,7.0))), Vectors.dense(2.0,0.0,3.0,4.0,5.0), Vectors.dense(4.0,0.0,0.0,6.0,7.0) ) valdf=spark.createDataFrame(data.map(Tuple1.apply)).toDF("features") valpca=newPCA() .setInputCol("features") .setOutputCol("pcaFeatures") .setK(3) .fit(df) valpcaDF=pca.transform(df) valresult=pcaDF.select("pcaFeatures") result.show() 由于是spark1.6.2。api有些不能用。 OneHotEncoder 算法介绍: 独热编码将标签指标映射为二值向量,其中最多一个单值。这种编码被用于将种类特征使用到需要连续特征的算法,如逻辑回归等。 scala代码 importorg.apache.spark.ml.feature.{OneHotEncoder,StringIndexer} valdf=spark.createDataFrame(Seq( (0,"a"), (1,"b"), (2,"c"), (3,"a"), (4,"a"), (5,"c") )).toDF("id","category") valindexer=newStringIndexer() .setInputCol("category") .setOutputCol("categoryIndex") .fit(df) valindexed=indexer.transform(df) valencoder=newOneHotEncoder() .setInputCol("categoryIndex") .setOutputCol("categoryVec") valencoded=encoder.transform(indexed) encoded.select("id","categoryVec").show() Python List numpy array numpy数组:元素只有一种类型,否则会转换成字符串。 不同的类型,不同的行为 numpy的构造子集 二维numpy数组 ndarray=n维数组 本文转自 chengxuyonghu 51CTO博客,原文链接:http://blog.51cto.com/6226001001/1895972,如需转载请自行联系原作者

优秀的个人博客,低调大师

pandas.DataFrame.reset_index

DataFrame. reset_index ( level=None, drop=False, inplace=False, col_level=0, col_fill='' ) [source] For DataFrame with multi-level index, return new DataFrame with labeling information in the columns under the index names, defaulting to ‘level_0’, ‘level_1’, etc. if any are None. For a standard index, the index name will be used (if set), otherwise a default ‘index’ or ‘level_0’ (if ‘index’ is already taken) will be used. Parameters: level: int, str, tuple, or list, default None Only remove the given levels from the index. Removes all levels by default drop: boolean, default False Do not try to insert index into dataframe columns. This resets the index to the default integer index. inplace: boolean, default False Modify the DataFrame in place (do not create a new object) col_level: int or str, default 0 If the columns have multiple levels, determines which level the labels are inserted into. By default it is inserted into the first level. col_fill: object, default ‘’ If the columns have multiple levels, determines how the other levels are named. If None then the index name is repeated. Returns: resetted: DataFrame Examples >>> df = pd.DataFrame([('bird', 389.0), ... ('bird', 24.0), ... ('mammal', 80.5), ... ('mammal', np.nan)], ... index=['falcon', 'parrot', 'lion', 'monkey'], ... columns=('class', 'max_speed')) >>> df class max_speed falcon bird 389.0 parrot bird 24.0 lion mammal 80.5 monkey mammal NaN When we reset the index, the old index is added as a column, and a new sequential index is used: >>> df.reset_index() index class max_speed 0 falcon bird 389.0 1 parrot bird 24.0 2 lion mammal 80.5 3 monkey mammal NaN We can use thedropparameter to avoid the old index being added as a column: >>> df.reset_index(drop=True) class max_speed 0 bird 389.0 1 bird 24.0 2 mammal 80.5 3 mammal NaN You can also usereset_indexwithMultiIndex. >>> index = pd.MultiIndex.from_tuples([('bird', 'falcon'), ... ('bird', 'parrot'), ... ('mammal', 'lion'), ... ('mammal', 'monkey')], ... names=['class', 'name']) >>> columns = pd.MultiIndex.from_tuples([('speed', 'max'), ... ('species', 'type')]) >>> df = pd.DataFrame([(389.0, 'fly'), ... ( 24.0, 'fly'), ... ( 80.5, 'run'), ... (np.nan, 'jump')], ... index=index, ... columns=columns) >>> df speed species max type class name bird falcon 389.0 fly parrot 24.0 fly mammal lion 80.5 run monkey NaN jump If the index has multiple levels, we can reset a subset of them: >>> df.reset_index(level='class') class speed species max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump If we are not dropping the index, by default, it is placed in the top level. We can place it in another level: >>> df.reset_index(level='class', col_level=1) speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump When the index is inserted under another level, we can specify under which one with the parametercol_fill: >>> df.reset_index(level='class', col_level=1, col_fill='species') species speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump If we specify a nonexistent level forcol_fill, it is created: >>> df.reset_index(level='class', col_level=1, col_fill='genus') genus speed species class max type name falcon bird 389.0 fly parrot bird 24.0 fly lion mammal 80.5 run monkey mammal NaN jump

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册