您的位置:首页 > 其它

Pandas Index对象

2017-05-24 13:20 204 查看
Index对象是通过有序的,可切片的集合实现的。

Index

属性(Attributes)

FunctionDescribe
Index.values返回索引的值
Index.is_monotonic_increasing是否是单调升的
Index.is_monotonic_decreasing是否是单调减的
Index.is_unique是否是唯一的
Index.has_duplicates
Index.dtype索引类型
Index.inferred_type
Index.is_all_dates
Index.shape索引的形状
Index.nbytes返回字节数
Index.ndim返回维度
Index.size返回元素的个数
Index.stridesreturn the strides of the underlying data
Index.itemsizereturn the size of the dtype of the item of the underlying data
Index.basereturn the base object if the memory of the underlying data is
Index.Treturn the transpose, which is by definition self
Index.memory_usage([deep])Memory usage of my values

修改和计算(Modifying and Computations)

FunctionDescribe
Index.all(*args,?**kwargs)Return whether all elements are True
Index.any(*args,?**kwargs)Return whether any element is True
Index.argmin([axis])return a ndarray of the minimum argument indexer
Index.argmax([axis])return a ndarray of the maximum argument indexer
Index.copy([name,?deep,?dtype])复制
Index.delete(loc)Make new Index with passed location(-s) deleted
Index.drop(labels[,?errors])Make new Index with passed list of labels deleted
Index.drop_duplicates(*args,?**kwargs)Return Index with duplicate values removed
Index.duplicated(*args,?**kwargs)Return boolean np.ndarray denoting duplicate values
Index.equals(other)是否含有相同的元素
Index.factorize([sort,?na_sentinel])Encode the object as an enumerated type or categorical variable
Index.identical(other)Similar to equals, but check that other comparable attributes are
Index.insert(loc,?item)Make new Index inserting new item at location.
Index.min()最小值
Index.max()最大值
Index.reindex(target[,?method,?level,?…])Create index with target’s values (move/add/delete values
4000
as necessary)
Index.repeat(n,?*args,?**kwargs)Repeat elements of an Index.
Index.where(cond[,?other])条件选取
Index.take(indices[, axis, allow_fill, …])return a new %(klass)s of the values selected by the indices
Index.putmask(mask, value)return a new Index of the values set with the mask
Index.set_names(names[, level, inplace])Set new names on index.
Index.unique()返回唯一值
Index.nunique([dropna])Return number of unique elements in the object.
Index.value_counts([normalize, sort, …])返回唯一值计数
Index.fillna([value, downcast])填充缺省值
Index.dropna([how])Return Index without NA/NaN values

转换(Conversion)

FunctionDescribe
Index.astype(dtype[,?copy])Create an Index with values cast to dtypes.
Index.tolist()转变为list
Index.to_series(**kwargs)Create a Series with both index and values equal to the index keys

排序(Sorting)

FunctionDescribe
Index.argsort(*args, **kwargs)Returns the indices that would sort the index and its underlying data.
Index.sort_values([return_indexer, ascending])Return sorted copy of Index

时间处理(Time-specific operations)

FunctionDescribe
Index.shift([periods,?freq])Shift Index containing datetime objects by input number of periods and

联表(Combining / joining / set operations)

FunctionDescribe
Index.append(other)Append a collection of Index options together
Index.join(other[, how, level, return_indexers])this is an internal non-public method
Index.intersection(other)Form the intersection of two Index objects.
Index.union(other)Form the union of two Index objects and sorts if possible.
Index.difference(other)Return a new Index with elements from the index that are not in other.
Index.symmetric_difference(other[, result_name])Compute the symmetric difference of two Index objects.

选取(Selecting)

FunctionDescribe
Index.get_indexer(target[, method, limit, …])Compute indexer and mask for new index given the current index.
Index.get_indexer_non_unique(target)return an indexer suitable for taking from a non unique index
Index.get_level_values(level)Return vector of label values for requested level, equal to the length
Index.get_loc(key[, method, tolerance])Get integer location for requested label
Index.get_value(series, key)Fast lookup of value from 1-dimensional ndarray.
Index.isin(values[, level])Compute boolean array of whether each index value is found in the passed set of values.
Index.slice_indexer([start, end, step, kind])For an ordered Index, compute the slice indexer for input labels and
Index.slice_locs([start, end, step, kind])Compute slice locations for input labels.

分类索引CategoricalIndex

FunctionDescribe
CategoricalIndexImmutable Index implementing an ordered, sliceable set.
CategoricalIndex.codes
CategoricalIndex.categories
CategoricalIndex.ordered
CategoricalIndex.rename_categories(*args, …)Renames categories.
CategoricalIndex.reorder_categories(*args, …)Reorders categories as specified in new_categories.
CategoricalIndex.add_categories(*args, **kwargs)Add new categories.
CategoricalIndex.remove_categories(*args, …)Removes the specified categories.
CategoricalIndex.remove_unused_categories(…)Removes categories which are not used.
CategoricalIndex.set_categories(*args, **kwargs)Sets the categories to the specified new_categories.
CategoricalIndex.as_ordered(*args, **kwargs)Sets the Categorical to be ordered
CategoricalIndex.as_unordered(*args, **kwargs)Sets the Categorical to be unordered

复合索引

FunctionDescribe
MultiIndex.from_arrays(arrays[, sortorder, …])Convert arrays to MultiIndex
MultiIndex.from_tuples(tuples[, sortorder, …])Convert list of tuples to MultiIndex
MultiIndex.from_product(iterables[, …])Make a MultiIndex from the cartesian product of multiple iterables
MultiIndex.set_levels(levels[, level, …])Set new levels on MultiIndex.
MultiIndex.set_labels(labels[, level, …])Set new labels on MultiIndex.
MultiIndex.to_hierarchical(n_repeat[, n_shuffle])Return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle.
MultiIndex.is_lexsorted()Return True if the labels are lexicographically sorted
MultiIndex.droplevel([level])Return Index with requested level removed.
MultiIndex.swaplevel([i, j])Swap level i with level j.
MultiIndex.reorder_levels(order)Rearrange levels using input order.

时间索引DatetimeIndex

属性

参考Series里面的Datetime类型的介绍

时间索引可以用字符串

“2011/01/01” 搜索某一天

“2011/01”搜索某一月,当月所有数据都会输出

FunctionDescribe
DatetimeIndex.yearThe year of the datetime
DatetimeIndex.monthThe month as January=1, December=12
DatetimeIndex.dayThe days of the datetime
DatetimeIndex.hourThe hours of the datetime
DatetimeIndex.minuteThe minutes of the datetime
DatetimeIndex.secondThe seconds of the datetime
DatetimeIndex.microsecondThe microseconds of the datetime
DatetimeIndex.nanosecondThe nanoseconds of the datetime
DatetimeIndex.dateReturns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
DatetimeIndex.timeReturns numpy array of datetime.time.
DatetimeIndex.dayofyearThe ordinal day of the year
DatetimeIndex.weekofyearThe week ordinal of the year
DatetimeIndex.weekThe week ordinal of the year
DatetimeIndex.dayofweekThe day of the week with Monday=0, Sunday=6
DatetimeIndex.weekdayThe day of the week with Monday=0, Sunday=6
DatetimeIndex.weekday_nameThe name of day in a week (ex: Friday)
DatetimeIndex.quarterThe quarter of the date
DatetimeIndex.tz
DatetimeIndex.freqget/set the frequncy of the Index
DatetimeIndex.freqstrReturn the frequency object as a string if its set, otherwise None
DatetimeIndex.is_month_startLogical indicating if first day of month (defined by frequency)
DatetimeIndex.is_month_endLogical indicating if last day of month (defined by frequency)
DatetimeIndex.is_quarter_startLogical indicating if first day of quarter (defined by frequency)
DatetimeIndex.is_quarter_endLogical indicating if last day of quarter (defined by frequency)
DatetimeIndex.is_year_startLogical indicating if first day of year (defined by frequency)
DatetimeIndex.is_year_endLogical indicating if last day of year (defined by frequency)
DatetimeIndex.is_leap_yearLogical indicating if the date belongs to a leap year
DatetimeIndex.inferred_freq

选取Selecting

FunctionDescribe
DatetimeIndex.indexer_at_time(time[, asof])Select values at particular time of day (e.g.
DatetimeIndex.indexer_between_time(…[, …])Select values between particular times of day (e.g., 9:00-9:30AM).

特定的时间方法

FunctionDescribe
DatetimeIndex.normalize()Return DatetimeIndex with times to midnight.
DatetimeIndex.strftime(date_format)Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library.
DatetimeIndex.snap([freq])Snap time stamps to nearest occurring frequency
DatetimeIndex.tz_convert(tz)Convert tz-aware DatetimeIndex from one time zone to another (using
DatetimeIndex.tz_localize(*args, **kwargs)Localize tz-naive DatetimeIndex to given time zone (using
DatetimeIndex.round(freq, *args, **kwargs)round the index to the specified freq
DatetimeIndex.floor(freq)floor the index to the specified freq
DatetimeIndex.ceil(freq)ceil the index to the specified freq

转化Conversion

FunctionDescribe
DatetimeIndex.to_datetime([dayfirst])
DatetimeIndex.to_period([freq])Cast to PeriodIndex at a particular frequency
DatetimeIndex.to_perioddelta(freq)Calcuates TimedeltaIndex of difference between index values and index converted to PeriodIndex at specified freq.
DatetimeIndex.to_pydatetime()Return DatetimeIndex as object ndarray of datetime.datetime objects
DatetimeIndex.to_series([keep_tz])Create a Series with both index and values equal to the index keys
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: