构造函数
Dataframe([data, index, columns, dtype, copy]) #构造数据框
属性和数据
Dataframe.axes #index: 行标签;columns: 列标签 Dataframe.as_matrix([columns]) #转换为矩阵 Dataframe.dtypes #返回数据的类型 Dataframe.ftypes #返回每一列的 数据类型float64:dense Dataframe.get_dtype_counts() #返回数据框数据类型的个数 Dataframe.get_ftype_counts() #返回数据框数据类型float64:dense的个数 Dataframe.select_dtypes([include, include]) #根据数据类型选取子数据框 Dataframe.values #Numpy的展示方式 Dataframe.axes #返回横纵坐标的标签名 Dataframe.ndim #返回数据框的纬度 Dataframe.size #返回数据框元素的个数 Dataframe.shape #返回数据框的形状 Dataframe.memory_usage() #每一列的存储
类型转换
Dataframe.astype(dtype[, copy, errors]) #转换数据类型 Dataframe.copy([deep]) #deep深度复制数据 Dataframe.isnull()#以布尔的方式返回空值 Dataframe.notnull()#以布尔的方式返回非空值
索引和迭代
Dataframe.head([n])#返回前n行数据 Dataframe.at #快速标签常量访问器 Dataframe.iat #快速整型常量访问器 Dataframe.loc #标签定位,使用名称 Dataframe.iloc #整型定位,使用数字 Dataframe.insert(loc, column, value) #在特殊地点loc[数字]插入column[列名]某列数据 Dataframe.iter() #Iterate over infor axis Dataframe.iteritems() #返回列名和序列的迭代器 Dataframe.iterrows() #返回索引和序列的迭代器 Dataframe.itertuples([index, name]) #Iterate over Dataframe rows as namedtuples, with index value as first element of the tuple. Dataframe.lookup(row_labels, col_labels) #Label-based “fancy indexing” function for Dataframe. Dataframe.pop(item)#返回删除的项目 Dataframe.tail([n])#返回最后n行 Dataframe.xs(key[, axis, level, drop_level]) #Returns a cross-section (row(s) or column(s)) from the Series/Dataframe. Dataframe.isin(values) #是否包含数据框中的元素 Dataframe.where(cond[, other, inplace, …]) #条件筛选 Dataframe.mask(cond[, other, inplace, …]) #Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other. Dataframe.query(expr[, inplace])#Query the columns of a frame with a boolean expression.
二元运算
Dataframe.add(other[,axis,fill_value]) #加法,元素指向 Dataframe.sub(other[,axis,fill_value]) #减法,元素指向 Dataframe.mul(other[, axis,fill_value]) #乘法,元素指向 Dataframe.div(other[, axis,fill_value]) #小数除法,元素指向 Dataframe.truediv(other[, axis, level, …]) #真除法,元素指向 Dataframe.floordiv(other[, axis, level, …]) #向下取整除法,元素指向 Dataframe.mod(other[, axis,fill_value]) #模运算,元素指向 Dataframe.pow(other[, axis,fill_value]) #幂运算,元素指向 Dataframe.radd(other[, axis,fill_value]) #右侧加法,元素指向 Dataframe.rsub(other[, axis,fill_value]) #右侧减法,元素指向 Dataframe.rmul(other[, axis,fill_value]) #右侧乘法,元素指向 Dataframe.rdiv(other[, axis,fill_value]) #右侧小数除法,元素指向 Dataframe.rtruediv(other[, axis, …]) #右侧真除法,元素指向 Dataframe.rfloordiv(other[, axis, …]) #右侧向下取整除法,元素指向 Dataframe.rmod(other[, axis,fill_value]) #右侧模运算,元素指向 Dataframe.rpow(other[, axis,fill_value]) #右侧幂运算,元素指向 Dataframe.lt(other[, axis, level]) #类似Array.lt Dataframe.gt(other[, axis, level]) #类似Array.gt Dataframe.le(other[, axis, level]) #类似Array.le Dataframe.ge(other[, axis, level]) #类似Array.ge Dataframe.ne(other[, axis, level]) #类似Array.ne Dataframe.eq(other[, axis, level]) #类似Array.eq Dataframe.combine(other,func[,fill_value, …]) #Add two Dataframe objects and do not propagate NaN values, so if for a Dataframe.combine_first(other) #Combine two Dataframe objects and default to non-null values in frame calling the method.
函数应用&分组&窗口
Dataframe.apply(func[, axis, broadcast, …]) #应用函数 Dataframe.applymap(func) #Apply a function to a Dataframe that is intended to operate elementwise, i.e. Dataframe.aggregate(func[, axis])#Aggregate using callable, string, dict, or list of string/callables Dataframe.transform(func, *args, **kwargs) #Call function producing a like-indexed NDframe Dataframe.groupby([by, axis, level, …]) #分组 Dataframe.rolling(window[, min_periods, …]) #滚动窗口 Dataframe.expanding([min_periods, freq, …]) #拓展窗口 Dataframe.ewm([com, span, halflife, …]) #指数权重窗口
描述统计学
Dataframe.abs() #返回绝对值 Dataframe.all([axis, bool_only, skipna]) #Return whether all elements are True over requested axis Dataframe.any([axis, bool_only, skipna]) #Return whether any element is True over requested axis Dataframe.clip([lower, upper, axis]) #Trim values at input threshold(s). Dataframe.clip_lower(threshold[, axis]) #Return copy of the input with values below given value(s) truncated. Dataframe.clip_upper(threshold[, axis]) #Return copy of input with values above given value(s) truncated. Dataframe.corr([method, min_periods]) #返回本数据框成对列的相关性系数 Dataframe.corrwith(other[, axis, drop]) #返回不同数据框的相关性 Dataframe.count([axis, level, numeric_only]) #返回非空元素的个数 Dataframe.cov([min_periods]) #计算协方差 Dataframe.cummax([axis, skipna])#Return cumulative max over requested axis. Dataframe.cummin([axis, skipna])#Return cumulative minimum over requested axis. Dataframe.cumprod([axis, skipna])#返回累积 Dataframe.cumsum([axis, skipna])#返回累和 Dataframe.describe([percentiles,include, …]) #整体描述数据框 Dataframe.diff([periods, axis]) #1st discrete difference of object Dataframe.eval(expr[, inplace]) #evaluate an expression in the context of the calling Dataframe instance. Dataframe.kurt([axis, skipna, level, …]) #返回无偏峰度Fisher's (kurtosis of normal == 0.0). Dataframe.mad([axis, skipna, level]) #返回偏差 Dataframe.max([axis, skipna, level, …]) #返回最大值 Dataframe.mean([axis, skipna, level, …]) #返回均值 Dataframe.median([axis, skipna, level, …]) #返回中位数 Dataframe.min([axis, skipna, level, …]) #返回最小值 Dataframe.mode([axis, numeric_only]) #返回众数 Dataframe.pct_change([periods, fill_method]) #返回百分比变化 Dataframe.prod([axis, skipna, level, …]) #返回连乘积 Dataframe.quantile([q, axis, numeric_only]) #返回分位数 Dataframe.rank([axis, method, numeric_only]) #返回数字的排序 Dataframe.round([decimals]) #Round a Dataframe to a variable number of decimal places. Dataframe.sem([axis, skipna, level, ddof]) #返回无偏标准误 Dataframe.skew([axis, skipna, level, …]) #返回无偏偏度 Dataframe.sum([axis, skipna, level, …]) #求和 Dataframe.std([axis, skipna, level, ddof]) #返回标准误差 Dataframe.var([axis, skipna, level, ddof]) #返回无偏误差
从新索引&选取&标签操作
Dataframe.add_prefix(prefix) #添加前缀 Dataframe.add_suffix(suffix) #添加后缀 Dataframe.align(other[, join, axis, level]) #Align two object on their axes with the Dataframe.drop(labels[, axis, level, …]) #返回删除的列 Dataframe.drop_duplicates([subset, keep, …]) #Return Dataframe with duplicate rows removed, optionally only Dataframe.duplicated([subset, keep]) #Return boolean Series denoting duplicate rows, optionally only Dataframe.equals(other) #两个数据框是否相同 Dataframe.filter([items, like, regex, axis]) #过滤特定的子数据框 Dataframe.first(offset) #Convenience method for subsetting initial periods of time series data based on a date offset. Dataframe.head([n])#返回前n行 Dataframe.idxmax([axis, skipna])#Return index of first occurrence of maximum over requested axis. Dataframe.idxmin([axis, skipna])#Return index of first occurrence of minimum over requested axis. Dataframe.last(offset) #Convenience method for subsetting final periods of time series data based on a date offset. Dataframe.reindex([index, columns]) #Conform Dataframe to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index. Dataframe.reindex_axis(labels[, axis, …]) #Conform input object to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index. Dataframe.reindex_like(other[, method, …]) #Return an object with matching indices to myself. Dataframe.rename([index, columns]) #Alter axes input function or functions. Dataframe.rename_axis(mapper[, axis, copy]) #Alter index and / or columns using input function or functions. Dataframe.reset_index([level, drop, …]) #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. Dataframe.sample([n, frac, replace, …]) #返回随机抽样 Dataframe.select(crit[, axis]) #Return data corresponding to axis labels matching criteria Dataframe.set_index(keys[, drop, append ]) #Set the Dataframe index (row labels) using one or more existing columns. Dataframe.tail([n])#返回最后几行 Dataframe.take(indices[, axis, convert]) #Analogous to ndarray.take Dataframe.truncate([before, after, axis ]) #Truncates a sorted NDframe before and/or after some particular index value.
处理缺失值
Dataframe.dropna([axis, how, thresh, …]) #Return object with labels on given axis omitted where alternately any Dataframe.fillna([value, method, axis, …]) #填充空值 Dataframe.replace([to_replace, value, …]) #Replace values given in ‘to_replace' with ‘value'.
从新定型&排序&转变形态
Dataframe.pivot([index, columns, values]) #Reshape data (produce a “pivot” table) based on column values. Dataframe.reorder_levels(order[, axis]) #Rearrange index levels using input order. Dataframe.sort_values(by[, axis, ascending]) #Sort by the values along either axis Dataframe.sort_index([axis, level, …]) #Sort object by labels (along an axis) Dataframe.nlargest(n, columns[, keep]) #Get the rows of a Dataframe sorted by the n largest values of columns. Dataframe.nsmallest(n, columns[, keep]) #Get the rows of a Dataframe sorted by the n smallest values of columns. Dataframe.swaplevel([i, j, axis])#Swap levels i and j in a MultiIndex on a particular axis Dataframe.stack([level, dropna])#Pivot a level of the (possibly hierarchical) column labels, returning a Dataframe (or Series in the case of an object with a single level of column labels) having a hierarchical index with a new inner-most level of row labels. Dataframe.unstack([level, fill_value]) #Pivot a level of the (necessarily hierarchical) index labels, returning a Dataframe having a new level of column labels whose inner-most level consists of the pivoted index labels. Dataframe.melt([id_vars, value_vars, …]) #“Unpivots” a Dataframe from wide format to long format, optionally Dataframe.T #Transpose index and columns Dataframe.to_panel() #Transform long (stacked) format (Dataframe) into wide (3D, Panel) format. Dataframe.to_xarray() #Return an xarray object from the pandas object. Dataframe.transpose(*args, **kwargs) #Transpose index and columns
Combining& joining&merging
Dataframe.append(other[, ignore_index, …]) #追加数据 Dataframe.assign(**kwargs) #Assign new columns to a Dataframe, returning a new object (a copy) with all the original columns in addition to the new ones. Dataframe.join(other[, on, how, lsuffix, …]) #Join columns with other Dataframe either on index or on a key column. Dataframe.merge(right[, how, on, left_on, …]) #Merge Dataframe objects by performing a database-style join operation by columns or indexes. Dataframe.update(other[, join, overwrite, …]) #Modify Dataframe in place using non-NA values from passed Dataframe.
时间序列
Dataframe.asfreq(freq[, method, how, …]) #将时间序列转换为特定的频次 Dataframe.asof(where[, subset]) #The last row without any NaN is taken (or the last row without Dataframe.shift([periods, freq, axis]) #Shift index by desired number of periods with an optional time freq Dataframe.first_valid_index() #Return label for first non-NA/null value Dataframe.last_valid_index() #Return label for last non-NA/null value Dataframe.resample(rule[, how, axis, …]) #Convenience method for frequency conversion and resampling of time series. Dataframe.to_period([freq, axis, copy]) #Convert Dataframe from DatetimeIndex to PeriodIndex with desired Dataframe.to_timestamp([freq, how, axis]) #Cast to DatetimeIndex of timestamps, at beginning of period Dataframe.tz_convert(tz[, axis, level, copy]) #Convert tz-aware axis to target time zone. Dataframe.tz_localize(tz[, axis, level, …]) #Localize tz-naive TimeSeries to target time zone.
作图
Dataframe.plot([x, y, kind, ax, ….]) #Dataframe plotting accessor and method Dataframe.plot.area([x, y]) #面积图Area plot Dataframe.plot.bar([x, y]) #垂直条形图Vertical bar plot Dataframe.plot.barh([x, y]) #水平条形图Horizontal bar plot Dataframe.plot.box([by]) #箱图Boxplot Dataframe.plot.density(**kwds) #核密度Kernel Density Estimate plot Dataframe.plot.hexbin(x, y[, C, …]) #Hexbin plot Dataframe.plot.hist([by, bins]) #直方图Histogram Dataframe.plot.kde(**kwds) #核密度Kernel Density Estimate plot Dataframe.plot.line([x, y]) #线图Line plot Dataframe.plot.pie([y]) #饼图Pie chart Dataframe.plot.scatter(x, y[, s, c]) #散点图Scatter plot Dataframe.boxplot([column, by, ax, …]) #Make a box plot from Dataframe column optionally grouped by some columns or Dataframe.hist(data[, column, by, grid, …]) #Draw histogram of the Dataframe's series using matplotlib / pylab.
转换为其他格式
Dataframe.from_csv(path[, header, sep, …]) #Read CSV file (DEPRECATED, please use pandas.read_csv() instead). Dataframe.from_dict(data[, orient, dtype]) #Construct Dataframe from dict of array-like or dicts Dataframe.from_items(items[,columns,orient]) #Convert (key, value) pairs to Dataframe. Dataframe.from_records(data[, index, …]) #Convert structured or record ndarray to Dataframe Dataframe.info([verbose, buf, max_cols, …]) #Concise summary of a Dataframe. Dataframe.to_pickle(path[, compression, …]) #Pickle (serialize) object to input file path. Dataframe.to_csv([path_or_buf, sep, na_rep]) #Write Dataframe to a comma-separated values (csv) file Dataframe.to_hdf(path_or_buf, key, **kwargs) #Write the contained data to an HDF5 file using HDFStore. Dataframe.to_sql(name, con[, flavor, …]) #Write records stored in a Dataframe to a SQL database. Dataframe.to_dict([orient, into])#Convert Dataframe to dictionary. Dataframe.to_excel(excel_writer[, …]) #Write Dataframe to an excel sheet Dataframe.to_json([path_or_buf, orient, …]) #Convert the object to a JSON string. Dataframe.to_html([buf, columns, col_space]) #Render a Dataframe as an HTML table. Dataframe.to_feather(fname) #write out the binary feather-format for Dataframes Dataframe.to_latex([buf, columns, …]) #Render an object to a tabular environment table. Dataframe.to_stata(fname[, convert_dates, …]) #A class for writing Stata binary dta files from array-like objects Dataframe.to_msgpack([path_or_buf, encoding]) #msgpack (serialize) object to input file path Dataframe.to_sparse([fill_value, kind]) #Convert to SparseDataframe Dataframe.to_dense() #Return dense representation of NDframe (as opposed to sparse) Dataframe.to_string([buf, columns, …]) #Render a Dataframe to a console-friendly tabular output. Dataframe.to_clipboard([excel, sep]) #Attempt to write text representation of object to the system clipboard This can be pasted into Excel, for example.
到此这篇关于Pandas中Dataframe基本函数整理(小结)的文章就介绍到这了,更多相关Pandas Dataframe基本函数内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!



