Pandas中DataFrame基本函數(shù)整理(小結(jié))
構(gòu)造函數(shù)
DataFrame([data, index, columns, dtype, copy]) #構(gòu)造數(shù)據(jù)框
屬性和數(shù)據(jù)
DataFrame.axes #index: 行標(biāo)簽;columns: 列標(biāo)簽 DataFrame.as_matrix([columns]) #轉(zhuǎn)換為矩陣 DataFrame.dtypes #返回?cái)?shù)據(jù)的類型 DataFrame.ftypes #返回每一列的 數(shù)據(jù)類型float64:dense DataFrame.get_dtype_counts() #返回?cái)?shù)據(jù)框數(shù)據(jù)類型的個(gè)數(shù) DataFrame.get_ftype_counts() #返回?cái)?shù)據(jù)框數(shù)據(jù)類型float64:dense的個(gè)數(shù) DataFrame.select_dtypes([include, include]) #根據(jù)數(shù)據(jù)類型選取子數(shù)據(jù)框 DataFrame.values #Numpy的展示方式 DataFrame.axes #返回橫縱坐標(biāo)的標(biāo)簽名 DataFrame.ndim #返回?cái)?shù)據(jù)框的緯度 DataFrame.size #返回?cái)?shù)據(jù)框元素的個(gè)數(shù) DataFrame.shape #返回?cái)?shù)據(jù)框的形狀 DataFrame.memory_usage() #每一列的存儲(chǔ)
類型轉(zhuǎn)換
DataFrame.astype(dtype[, copy, errors]) #轉(zhuǎn)換數(shù)據(jù)類型 DataFrame.copy([deep]) #deep深度復(fù)制數(shù)據(jù) DataFrame.isnull() #以布爾的方式返回空值 DataFrame.notnull() #以布爾的方式返回非空值
索引和迭代
DataFrame.head([n]) #返回前n行數(shù)據(jù) DataFrame.at #快速標(biāo)簽常量訪問器 DataFrame.iat #快速整型常量訪問器 DataFrame.loc #標(biāo)簽定位,使用名稱 DataFrame.iloc #整型定位,使用數(shù)字 DataFrame.insert(loc, column, value) #在特殊地點(diǎn)loc[數(shù)字]插入column[列名]某列數(shù)據(jù) 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) #返回刪除的項(xiàng)目 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) #是否包含數(shù)據(jù)框中的元素 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.
二元運(yùn)算
DataFrame.add(other[,axis,fill_value]) #加法,元素指向 DataFrame.sub(other[,axis,fill_value]) #減法,元素指向 DataFrame.mul(other[, axis,fill_value]) #乘法,元素指向 DataFrame.div(other[, axis,fill_value]) #小數(shù)除法,元素指向 DataFrame.truediv(other[, axis, level, …]) #真除法,元素指向 DataFrame.floordiv(other[, axis, level, …]) #向下取整除法,元素指向 DataFrame.mod(other[, axis,fill_value]) #模運(yùn)算,元素指向 DataFrame.pow(other[, axis,fill_value]) #冪運(yùn)算,元素指向 DataFrame.radd(other[, axis,fill_value]) #右側(cè)加法,元素指向 DataFrame.rsub(other[, axis,fill_value]) #右側(cè)減法,元素指向 DataFrame.rmul(other[, axis,fill_value]) #右側(cè)乘法,元素指向 DataFrame.rdiv(other[, axis,fill_value]) #右側(cè)小數(shù)除法,元素指向 DataFrame.rtruediv(other[, axis, …]) #右側(cè)真除法,元素指向 DataFrame.rfloordiv(other[, axis, …]) #右側(cè)向下取整除法,元素指向 DataFrame.rmod(other[, axis,fill_value]) #右側(cè)模運(yùn)算,元素指向 DataFrame.rpow(other[, axis,fill_value]) #右側(cè)冪運(yùn)算,元素指向 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.
函數(shù)應(yīng)用&分組&窗口
DataFrame.apply(func[, axis, broadcast, …]) #應(yīng)用函數(shù) 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, …]) #滾動(dòng)窗口 DataFrame.expanding([min_periods, freq, …]) #拓展窗口 DataFrame.ewm([com, span, halflife, …]) #指數(shù)權(quán)重窗口
描述統(tǒng)計(jì)學(xué)
DataFrame.abs() #返回絕對(duì)值 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]) #返回本數(shù)據(jù)框成對(duì)列的相關(guān)性系數(shù) DataFrame.corrwith(other[, axis, drop]) #返回不同數(shù)據(jù)框的相關(guān)性 DataFrame.count([axis, level, numeric_only]) #返回非空元素的個(gè)數(shù) DataFrame.cov([min_periods]) #計(jì)算協(xié)方差 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, …]) #整體描述數(shù)據(jù)框 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, …]) #返回?zé)o偏峰度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, …]) #返回中位數(shù) DataFrame.min([axis, skipna, level, …]) #返回最小值 DataFrame.mode([axis, numeric_only]) #返回眾數(shù) DataFrame.pct_change([periods, fill_method]) #返回百分比變化 DataFrame.prod([axis, skipna, level, …]) #返回連乘積 DataFrame.quantile([q, axis, numeric_only]) #返回分位數(shù) DataFrame.rank([axis, method, numeric_only]) #返回?cái)?shù)字的排序 DataFrame.round([decimals]) #Round a DataFrame to a variable number of decimal places. DataFrame.sem([axis, skipna, level, ddof]) #返回?zé)o偏標(biāo)準(zhǔn)誤 DataFrame.skew([axis, skipna, level, …]) #返回?zé)o偏偏度 DataFrame.sum([axis, skipna, level, …]) #求和 DataFrame.std([axis, skipna, level, ddof]) #返回標(biāo)準(zhǔn)誤差 DataFrame.var([axis, skipna, level, ddof]) #返回?zé)o偏誤差
從新索引&選取&標(biāo)簽操作
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) #兩個(gè)數(shù)據(jù)框是否相同 DataFrame.filter([items, like, regex, axis]) #過濾特定的子數(shù)據(jù)框 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, …]) #返回隨機(jī)抽樣 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'.
從新定型&排序&轉(zhuǎn)變形態(tài)
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, …]) #追加數(shù)據(jù) 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.
時(shí)間序列
DataFrame.asfreq(freq[, method, how, …]) #將時(shí)間序列轉(zhuǎn)換為特定的頻次 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]) #散點(diǎn)圖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.
轉(zhuǎn)換為其他格式
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.
到此這篇關(guān)于Pandas中DataFrame基本函數(shù)整理(小結(jié))的文章就介紹到這了,更多相關(guān)Pandas DataFrame基本函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Python實(shí)現(xiàn)傻瓜式GIF制作工具
有沒有什么內(nèi)容形式,比小視頻更小,比普通圖片更豐富?有,GIF動(dòng)態(tài)圖就是其中一種形式。本文將為大家介紹如何通過Python實(shí)現(xiàn)一個(gè)傻瓜式的gif生成工具,感興趣的可以了解一下2021-12-12爬山算法簡(jiǎn)介和Python實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了爬山算法,爬山法(climbing method)是一種優(yōu)化算法,其一般從一個(gè)隨機(jī)的解開始,然后逐步找到一個(gè)最優(yōu)解(局部最優(yōu))然后用Python實(shí)現(xiàn)了這個(gè)算法,需要的朋友可以參考下2014-04-04python教程之用py2exe將PY文件轉(zhuǎn)成EXE文件
py2exe是一個(gè)將python腳本轉(zhuǎn)換成windows上的可獨(dú)立執(zhí)行的可執(zhí)行程序(*.exe)的工具,這樣,你就可以不用裝python而在windows系統(tǒng)上運(yùn)行這個(gè)可執(zhí)行程序。2014-06-06python tornado上傳文件功能實(shí)現(xiàn)(前端和后端)
Tornado 是一個(gè)功能強(qiáng)大的 Web 框架,除了基本的請(qǐng)求處理能力之外,還提供了一些高級(jí)功能,在 Tornado web 框架中,上傳圖片通常涉及創(chuàng)建一個(gè)表單,讓用戶選擇文件并上傳,本文介紹tornado上傳文件功能,感興趣的朋友一起看看吧2024-03-03Pytest測(cè)試報(bào)告工具Allure的高級(jí)用法
這篇文章介紹了Pytest測(cè)試報(bào)告工具Allure的高級(jí)用法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07