Pandas Index对象
2017-05-24 13:20
204 查看
Index对象是通过有序的,可切片的集合实现的。
时间索引可以用字符串
“2011/01/01” 搜索某一天
“2011/01”搜索某一月,当月所有数据都会输出
Index
属性(Attributes)
Function | Describe |
---|---|
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.strides | return the strides of the underlying data |
Index.itemsize | return the size of the dtype of the item of the underlying data |
Index.base | return the base object if the memory of the underlying data is |
Index.T | return the transpose, which is by definition self |
Index.memory_usage([deep]) | Memory usage of my values |
修改和计算(Modifying and Computations)
Function | Describe |
---|---|
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)
Function | Describe |
---|---|
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)
Function | Describe |
---|---|
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)
Function | Describe |
---|---|
Index.shift([periods,?freq]) | Shift Index containing datetime objects by input number of periods and |
联表(Combining / joining / set operations)
Function | Describe |
---|---|
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)
Function | Describe |
---|---|
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
Function | Describe |
---|---|
CategoricalIndex | Immutable 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 |
复合索引
Function | Describe |
---|---|
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”搜索某一月,当月所有数据都会输出
Function | Describe |
---|---|
DatetimeIndex.year | The year of the datetime |
DatetimeIndex.month | The month as January=1, December=12 |
DatetimeIndex.day | The days of the datetime |
DatetimeIndex.hour | The hours of the datetime |
DatetimeIndex.minute | The minutes of the datetime |
DatetimeIndex.second | The seconds of the datetime |
DatetimeIndex.microsecond | The microseconds of the datetime |
DatetimeIndex.nanosecond | The nanoseconds of the datetime |
DatetimeIndex.date | Returns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information). |
DatetimeIndex.time | Returns numpy array of datetime.time. |
DatetimeIndex.dayofyear | The ordinal day of the year |
DatetimeIndex.weekofyear | The week ordinal of the year |
DatetimeIndex.week | The week ordinal of the year |
DatetimeIndex.dayofweek | The day of the week with Monday=0, Sunday=6 |
DatetimeIndex.weekday | The day of the week with Monday=0, Sunday=6 |
DatetimeIndex.weekday_name | The name of day in a week (ex: Friday) |
DatetimeIndex.quarter | The quarter of the date |
DatetimeIndex.tz | |
DatetimeIndex.freq | get/set the frequncy of the Index |
DatetimeIndex.freqstr | Return the frequency object as a string if its set, otherwise None |
DatetimeIndex.is_month_start | Logical indicating if first day of month (defined by frequency) |
DatetimeIndex.is_month_end | Logical indicating if last day of month (defined by frequency) |
DatetimeIndex.is_quarter_start | Logical indicating if first day of quarter (defined by frequency) |
DatetimeIndex.is_quarter_end | Logical indicating if last day of quarter (defined by frequency) |
DatetimeIndex.is_year_start | Logical indicating if first day of year (defined by frequency) |
DatetimeIndex.is_year_end | Logical indicating if last day of year (defined by frequency) |
DatetimeIndex.is_leap_year | Logical indicating if the date belongs to a leap year |
DatetimeIndex.inferred_freq |
选取Selecting
Function | Describe |
---|---|
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). |
特定的时间方法
Function | Describe |
---|---|
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
Function | Describe |
---|---|
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 |
相关文章推荐
- Pandas 索引对象(Index)
- Pandas详解三之Index对象
- pandas (3) Index对象
- pandas删除重复index
- Lua笔记19 面向对象实现__index
- pandas做数据分析(一):基本数据对象
- Pandas——NaN&Pivot&dropna&reset_index
- index获取子DOM对象在父DOM对象的内位置索引值
- pandas索引对象
- JS:1.8字符串(string)对象(length,indexOf(),lastIndexOf(),replace(),match(),toUpperCase(),toLowerCase())
- 当pandas.Series存在混合类型index的时候取子集出错的处理
- Flex 组件 重设对象的深度:setChildIndex
- oracle 学习笔记(十一) 数据库常用对象, table ,constraint ,index ,view和数据字典
- Pandas 对象储存
- Pandas index详解
- pandas contact 之后,一定要记得用reset_index去处理index,不然容易出现莫名的逻辑错误
- 【跟着stackoverflow学Pandas】--Converting a Pandas GroupBy object to DataFrame-Groupby对象转换为DataFrame
- 如何获取整个schema的DDL ,除了表和index 其他所有对象包括权限!
- jquery获取当前匹配对象的索引(index)
- 可变数据删除多个不连续index对象