1. ホーム
  2. python

[Python】PandasのDataFrame基本関数 (full)

2022-02-09 22:28:25
<パス
コンストラクター
DataFrame([data, index, columns, dtype, copy]) #Construct the data frame

属性とデータ
DataFrame.axes #index: row labels; columns: column labels
DataFrame.as_matrix([columns]) #convert to matrix
DataFrame.dtypes #the type of data to return
DataFrame.ftypes # return the data type of each column float64:dense
DataFrame.get_dtype_counts() #returns the number of data types in the data frame
DataFrame.get_ftype_counts() #returns the number of data types float64:dense in the data frame
DataFrame.select_dtypes([include, include]) #Select sub-data frames based on data type
DataFrame.values #Numpy's presentation
DataFrame.axes #returns the label names of the horizontal and vertical coordinates
DataFrame.ndim #Returns the latitude of the data frame
DataFrame.size #returns the number of elements in the data frame
DataFrame.shape #returns the shape of the data frame
DataFrame.memory_usage() # the storage for each column

型式変換
DataFrame.astype(dtype[, copy, errors]) #convert data type
DataFrame.copy([deep]) #deep copy data
DataFrame.isnull() #returns null as a boolean
DataFrame.notnull() #returns a non-null value as a boolean

インデックスとイテレーション
DataFrame.head([n]) # return the first n rows of data
DataFrame.at #fast label constant accessor
DataFrame.iat #quick integer constant accessor
DataFrame.loc #label positioning, using name
DataFrame.iloc #integer positioning, using numbers
DataFrame.insert(loc, column, value) #insert column[column name] data in a special location loc[number]
DataFrame.iter() #Iterate over infor axis
DataFrame.iteritems() #Return column names and iterators of the sequence
DataFrame.iterrows() #Iterate over indexes and sequences
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) #return the deleted item
DataFrame.tail([n]) #return the last n rows
DataFrame.xs(key[, axis, level, drop_level]) #Returns a cross-section (row(s) or column(s)) from the Series/DataFrame.
DataFrame.isin(values) #Includes the elements of the data frame or not
DataFrame.where(cond[, other, inplace, ...]) #conditional filtering
DataFrame.mask(cond[, other, inplace, ...]) #Return an object of the 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]) #add, element points to
DataFrame.sub(other[,axis,fill_value]) #subtract, element points to
DataFrame.mul(other[, axis,fill_value]) #multiply, element pointing
DataFrame.div(other[, axis,fill_value]) #decimal division, element points to
DataFrame.truediv(other[, axis, level, ...]) #true divide, element points to
DataFrame.floordiv(other[, axis, level, ...]) #Divide down, element points to
DataFrame.mod(other[, axis,fill_value]) #Modulo operation, element points to
DataFrame.pow(other[, axis,fill_value]) # power operation, element pointing
DataFrame.radd(other[, axis,fill_value]) # right-side addition, element pointing
DataFrame.rsub(other[, axis,fill_value]) # right-side subtraction, element pointing
DataFrame.rmul(other[, axis,fill_value]) #Multiply on the right, element points to
DataFrame.rdiv(other[, axis,fill_value]) #right-side decimal division, element points to
DataFrame.rtruediv(other[, axis, ...]) #right-hand side true division, element points to
DataFrame.rfloordiv(other[, axis, ...]) #right-hand side down division, element points to
DataFrame.rmod(other[, axis,fill_value]) #modulize on the right, element points to
DataFrame.rpow(other[, axis,fill_value]) #Right-hand side power operation, element points to
DataFrame.lt(other[, axis, level]) # similar to Array.lt
DataFrame.gt(other[, axis, level]) # similar to Array.gt
DataFrame.le(other[, axis, level]) # similar to Array.le
DataFrame.ge(other[, axis, level]) # similar to Array.ge
DataFrame.ne(other[, axis, level]) # similar to Array.ne
DataFrame.eq(other[, axis, level]) # similar to 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.


関数 application&group&window
DataFrame.apply(func[, axis, broadcast, ...]) #Apply a function
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, ...]) #group
DataFrame.scrolling(window[, min_periods, ...]) #Scrolling window
DataFrame.expanding([min_periods, freq, ...]) #Expanding window
DataFrame.ewm([com, span, halflife, ...]) #Exponential weights window

統計情報を記述する
DataFrame.abs() #Return the absolute value
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 the input with values above given value(s) truncated.
DataFrame.corr([method, min_periods]) #Return the correlation coefficient of pairs of columns in this data frame
DataFrame.corrwith(other[, axis, drop]) #return the correlation of different data frames
DataFrame.count([axis, level, numeric_only]) # return the number of non-empty elements
DataFrame.cov([min_periods]) # calculate the covariance
DataFrame.cummax([axis, skipna]) #Return cumulative max over requested axis.
DataFrame.cummin([axis, skipna]) #Return cumulative minimum over requested axis.
DataFrame.cumprod([axis, skipna]) #Return cumulative
DataFrame.cumsum([axis, skipna]) #Return cumulative sum
DataFrame.describe([percentiles, include, ...]) # describe the data frame as a whole
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, ...]) #Return unskewed kurtosis Fisher's (kurtosis of normal == 0.0).
DataFrame.mad([axis, skipna, level]) #return bias
DataFrame.max([axis, skipna, level, ...]) # return the maximum value
DataFrame.mean([axis, skipna, level, ...]) #return the mean value
DataFrame.median([axis, skipna, level, ...]) #returns the median
DataFrame.min([axis, skipna, level, ...]) # return the minimum value
DataFrame.mode([axis, numeric_only]) # return the plural
DataFrame.pct_change([periods, fill_method]) # return percentage change
DataFrame.prod([axis, skipna, level, ...]) #return to the product of even multiplication
DataFrame.quantile([q, axis, numeric_only]) #return to quantile
DataFrame.rank([axis, method, numeric_only]) #returns the ranking of numbers
DataFrame.round([decimals]) #Round a DataFrame to a variable number of decimal places.
DataFrame.sem([axis, skipna, level, ddof]) #Return unbiased standard errors
DataFrame.skew([axis, skipna, level, ...]) #return unbiased skew
DataFrame.sum([axis, skipna, level, ...]) #Sum up
DataFrame.std([axis, skipna, level, ddof]) #return standard error
DataFrame.var([axis, skipna, level, ddof]) #return unbiased error 

新しいindex&pick&labelの操作から
DataFrame.add_prefix(prefix) #add prefix
DataFrame.add_suffix(suffix) #add suffix
DataFrame.align(other[, join, axis, level]) #Align two objects on their axes with the
DataFrame.drop(labels[, axis, level, ...]) #return the deleted columns
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) #Whether two data frames are identical
DataFrame.filter([items, like, regex, axis]) #filter specific sub-data frames
DataFrame.first(offset) #Convenience method for subsetting initial periods of time series data based on a date offset.
DataFrame.head([n]) #return the first n rows
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. 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, ...]) # return a random sample
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]) #return the last few rows
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, ...]) #Fill with empty values
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.nlsmallest(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

結合・合流・合体
DataFrame.append(other[, ignore_index, ...]) #Append data
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, ...]) #Convert the time series to a specific frequency
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. example.