Pandas Series

http://pandas-docs.github.io/pandas-docs-travis/api.html

构造方法

方法描述
Series([data, index, dtype, name, copy, …])一维序列

属性

方法描述
Series.index轴标签
Series.values返回序列的数值
Series.dtype返回数据的类型
Series.ftypereturn if the data is sparse
Series.shape返回数据的型状
Series.nbytes返回数据的字节数
Series.ndim返回数据的维度
Series.size返回元素的个数
Series.stridesreturn the strides of the underlying data
Series.itemsizereturn the size of the dtype of the item of the underlying data
Series.basereturn the base object if the memory of the underlying data is
Series.T返回转置
Series.memory_usage([index, deep])Memory usage of the Series

转换

方法描述
Series.astype(dtype[, copy, raise_on_error])Cast object to input numpy.dtype
Series.copy([deep])复制Series
Series.isnull()测定是null,返回布尔值
Series.notnull()测定不是null,返回布尔值

索引和迭代

方法描述
Series.get(key[, default])返回所要得到的值
Series.at快速的标量访问器,使用标签
Series.iat快速的标量访问器,使用整型
Series.ix只能快速访问器,先使用标签,再使用整型
Series.loc标签索引
Series.iloc整型索引
Series.iter()序列值迭代器
Series.iteritems()惰性迭代器,返回索引和值

二元运算

方法描述
Series.add(other[, level, fill_value, axis])加法,元素指向
Series.sub(other[, level, fill_value, axis])减法,元素指向
Series.mul(other[, level, fill_value, axis])乘法,元素指向
Series.div(other[, level, fill_value, axis])除法,元素指向,结果为浮点
Series.truediv(other[, level, fill_value, axis])真除法,元素指向
Series.floordiv(other[, level, fill_value, axis])向下取整除法,元素指向
Series.mod(other[, level, fill_value, axis])模运算,元素指向
Series.pow(other[, level, fill_value, axis])幂运算,元素指向
Series.radd(other[, level, fill_value, axis])右侧加法,元素指向
Series.rsub(other[, level, fill_value, axis])右侧减法,元素指向
Series.rmul(other[, level, fill_value, axis])右侧乘法,元素指向
Series.rdiv(other[, level, fill_value, axis])右侧除法,元素指向
Series.rtruediv(other[, level, fill_value, axis])真右侧除法,元素指向
Series.rfloordiv(other[, level, fill_value, …])向下取整右侧除法,元素指向
Series.rmod(other[, level, fill_value, axis])右侧模运算,元素指向
Series.rpow(other[, level, fill_value, axis])右侧幂运算,元素指向
Series.combine(other, func[, fill_value])Perform elementwise binary operation on two Series using given function
Series.combine_first(other)Combine Series values, choosing the calling Series’s values first.
Series.round([decimals])随机抽取序列的值
Series.lt(other[, level, fill_value, axis])小于另一个序列,元素指向
Series.gt(other[, level, fill_value, axis])大于另一个序列,元素指向
Series.le(other[, level, fill_value, axis])小于等于另一个序列,元素指向
Series.ge(other[, level, fill_value, axis])大于等于另一个序列,元素指向
Series.ne(other[, level, fill_value, axis])不等于另一个序列,元素指向
Series.eq(other[, level, fill_value, axis])等于另一个序列,元素指向

函数应用&分组&窗口

方法描述
Series.apply(func[, convert_dtype, args])Invoke function on values of Series.
Series.map(arg[, na_action])Map values of Series using input correspondence (which can be
Series.groupby([by, axis, level, as_index, …])分组
Series.rolling(window[, min_periods, freq, …])移动窗口
Series.expanding([min_periods, freq, …])扩展窗口
Series.ewm([com, span, halflife, alpha, …])指数权重窗口

描述统计学

方法描述
Series.abs()绝对值
Series.all([axis, bool_only, skipna, level])Return whether all elements are True over requested axis
Series.any([axis, bool_only, skipna, level])Return whether any element is True over requested axis
Series.autocorr([lag])Lag-N autocorrelation
Series.between(left, right[, inclusive])Return boolean Series equivalent to left <= series <= right.
Series.clip([lower, upper, axis])Trim values at input threshold(s).
Series.clip_lower(threshold[, axis])Return copy of the input with values below given value(s) truncated.
Series.clip_upper(threshold[, axis])Return copy of input with values above given value(s) truncated.
Series.corr(other[, method, min_periods])相关性
Series.count([level])返回序列数据个数
Series.cov(other[, min_periods])协方差
Series.cummax([axis, skipna])Return cumulative max over requested axis.
Series.cummin([axis, skipna])Return cumulative minimum over requested axis.
Series.cumprod([axis, skipna])累乘
Series.cumsum([axis, skipna])累加
Series.describe([percentiles, include, exclude])描述
Series.diff([periods])1st discrete difference of object
Series.factorize([sort, na_sentinel])Encode the object as an enumerated type or categorical variable
Series.kurt([axis, skipna, level, numeric_only])峰度
Series.mad([axis, skipna, level])局对平均偏差
Series.max([axis, skipna, level, numeric_only])最大值
Series.mean([axis, skipna, level, numeric_only])平均值
Series.median([axis, skipna, level, …])中位数
Series.min([axis, skipna, level, numeric_only])最小值
Series.mode()Returns the mode(s) of the dataset.
Series.nlargest(*args, **kwargs)Return the largest n elements.
Series.nsmallest(*args, **kwargs)Return the smallest n elements.
Series.pct_change([periods, fill_method, …])增长率
Series.prod([axis, skipna, level, numeric_only])乘积
Series.quantile([q, interpolation])分位数
Series.rank([axis, method, numeric_only, …])排名
Series.sem([axis, skipna, level, ddof, …])Return unbiased standard error of the mean over requested axis.
Series.skew([axis, skipna, level, numeric_only])偏度
Series.std([axis, skipna, level, ddof, …])标准差
Series.sum([axis, skipna, level, numeric_only])求和
Series.var([axis, skipna, level, ddof, …])方差
Series.unique()返回唯一值
Series.nunique([dropna])R返回唯一值的个数
Series.is_unique是否为唯一值
Series.is_monotonicReturn boolean if values in the object are
Series.is_monotonic_increasingReturn boolean if values in the object are
Series.is_monotonic_decreasingReturn boolean if values in the object are
Series.value_counts([normalize, sort, …])唯一值计数

从新索引&选择&标签操控

方法描述
Series.align(other[, join, axis, level, …])Align two object on their axes with the
Series.drop(labels[, axis, level, inplace, …])返回移除的数据
Series.drop_duplicates(*args, **kwargs)Return Series with duplicate values removed
Series.duplicated(*args, **kwargs)Return boolean Series denoting duplicate values
Series.equals(other)是否含有相同的元素
Series.first(offset)Convenience method for subsetting initial periods of time series data based on a date offset.
Series.head([n])返回前n行
Series.idxmax([axis, skipna])Index of first occurrence of maximum of values.
Series.idxmin([axis, skipna])返回最小值的索引
Series.isin(values)是否包含序列的元素
Series.last(offset)Convenience method for subsetting final periods of time series data based on a date offset.
Series.reindex([index])Conform Series to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index.
Series.reindex_like(other[, method, copy, …])Return an object with matching indices to myself.
Series.rename([index])Alter axes input function or functions.
Series.rename_axis(mapper[, axis, copy, inplace])Alter index and / or columns using input function or functions.
Series.reset_index([level, drop, name, inplace])Analogous to the pandas.DataFrame.reset_index() function, see docstring there.
Series.sample([n, frac, replace, weights, …])随机抽样
Series.select(crit[, axis])Return data corresponding to axis labels matching criteria
Series.take(indices[, axis, convert, is_copy])return Series corresponding to requested indices
Series.tail([n])返回最后几行
Series.truncate([before, after, axis, copy])Truncates a sorted NDFrame before and/or after some particular index value.
Series.where(cond[, other, inplace, axis, …])条件选择
Series.mask(cond[, other, inplace, axis, …])Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other.

处理缺失值

方法描述
Series.dropna([axis, inplace])返回没有缺失值的序列
Series.fillna([value, method, axis, …])填充缺失值
Series.interpolate([method, axis, limit, …])Interpolate values according to different methods.

重塑&排序

方法描述
Series.argsort([axis, kind, order])Overrides ndarray.argsort.
Series.reorder_levels(order)Rearrange index levels using input order.
Series.sort_values([axis, ascending, …])Sort by the values along either axis
Series.sort_index([axis, level, ascending, …])Sort object by labels (along an axis)
Series.sortlevel([level, ascending, …])Sort Series with MultiIndex by chosen level.
Series.swaplevel([i, j, copy])Swap levels i and j in a MultiIndex
Series.unstack([level, fill_value])Unstack, a.k.a.
Series.searchsorted(v[, side, sorter])Find indices where elements should be inserted to maintain order.

Combining&joining&merging

方法描述
Series.append(to_append[, ignore_index, …])Concatenate two or more Series.
Series.replace([to_replace, value, inplace, …])Replace values given in ‘to_replace’ with ‘value’.
Series.update(other)Modify Series in place using non-NA values from passed Series.

时间序列相关

方法描述
Series.asfreq(freq[, method, how, normalize])将时间序列转换为特定的频率
Series.asof(where[, subset])The last row without any NaN is taken (or the last row without
Series.shift([periods, freq, axis])Shift index by desired number of periods with an optional time freq
Series.first_valid_index()Return label for first non-NA/null value
Series.last_valid_index()Return label for last non-NA/null value
Series.resample(rule[, how, axis, …])Convenience method for frequency conversion and resampling of time series.
Series.tz_convert(tz[, axis, level, copy])Convert tz-aware axis to target time zone.
Series.tz_localize(*args, **kwargs)Localize tz-naive TimeSeries to target time zone.

类似Datetime类型的属性

DateTime属性

方法描述
Series.dt.dateReturns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
Series.dt.timeReturns numpy array of datetime.time.
Series.dt.year返回年份
Series.dt.month返回月份
Series.dt.day返回天
Series.dt.hour返回小时
Series.dt.minute返回分钟
Series.dt.second返回秒
Series.dt.microsecond返回微秒
Series.dt.nanosecond返回纳秒
Series.dt.week返回周在年份中的名次
Series.dt.weekofyear返回周在年份中的名次
Series.dt.dayofweek返回日在周中的名次 Monday=0, Sunday=6
Series.dt.weekday返回日在周中的名次Monday=0, Sunday=6
Series.dt.weekday_name返回周中日的名字 (ex: Friday)
Series.dt.dayofyear返回日在年中的名次
Series.dt.quarter季度
Series.dt.is_month_start是否是月份的第一天
Series.dt.is_month_end是否是月份的最后一天
Series.dt.is_quarter_start是否是季度的第一天
Series.dt.is_quarter_end是否是季度的最后一天
Series.dt.is_year_start是否是年的第一天
Series.dt.is_year_end是否是年的最后一天
Series.dt.is_leap_yearLogical indicating if the date belongs to a leap year
Series.dt.daysinmonth月份一共有多少天
Series.dt.days_in_month月份一共有多少天
Series.dt.freqget/set the frequncy of the Index

DateTime方法

方法描述
Series.dt.to_period(*args, **kwargs)Cast to PeriodIndex at a particular frequency
Series.dt.to_pydatetime()
Series.dt.tz_localize(*args, **kwargs)Localize tz-naive DatetimeIndex to given time zone (using
Series.dt.tz_convert(*args, **kwargs)Convert tz-aware DatetimeIndex from one time zone to another (using
Series.dt.normalize(*args, **kwargs)Return DatetimeIndex with times to midnight.
Series.dt.strftime(*args, **kwargs)Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library.
Series.dt.round(*args, **kwargs)round the index to the specified freq
Series.dt.floor(*args, **kwargs)floor the index to the specified freq
Series.dt.ceil(*args, **kwargs)ceil the index to the specified freq

Timedelta属性

方法描述
Series.dt.daysNumber of days for each element.
Series.dt.secondsNumber of seconds (>= 0 and less than 1 day) for each element.
Series.dt.microsecondsNumber of microseconds (>= 0 and less than 1 second) for each element.
Series.dt.nanosecondsNumber of nanoseconds (>= 0 and less than 1 microsecond) for each element.
Series.dt.componentsReturn a dataframe of the components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of the Timedeltas.

Timedelta方法

方法描述
Series.dt.to_pytimedelta()
Series.dt.total_seconds(*args, **kwargs)Total duration of each element expressed in seconds.

字符串处理

方法描述
Series.str.capitalize()首字母大写
Series.str.cat([others, sep, na_rep])连接字符串
Series.str.center(width[, fillchar])Filling left and right side of strings in the Series/Index with an additional character.
Series.str.contains(pat[, case, flags, na, …])是否包含
Series.str.count(pat[, flags])Count occurrences of pattern in each string of the Series/Index.
Series.str.decode(encoding[, errors])Decode character string in the Series/Index using indicated encoding.
Series.str.encode(encoding[, errors])Encode character string in the Series/Index using indicated encoding.
Series.str.endswith(pat[, na])是否以…结尾
Series.str.extract(pat[, flags, expand])For each subject string in the Series, extract groups from the first match of regular expression pat.
Series.str.extractall(pat[, flags])For each subject string in the Series, extract groups from all matches of regular expression pat.
Series.str.find(sub[, start, end])Return lowest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
Series.str.findall(pat[, flags])Find all occurrences of pattern or regular expression in the Series/Index.
Series.str.get(i)Extract element from lists, tuples, or strings in each element in the Series/Index.
Series.str.index(sub[, start, end])Return lowest indexes in each strings where the substring is fully contained between [start:end].
Series.str.join(sep)Join lists contained as elements in the Series/Index with passed delimiter.
Series.str.len()计算所有的长度
Series.str.ljust(width[, fillchar])Filling right side of strings in the Series/Index with an additional character.
Series.str.lower()小写
Series.str.lstrip([to_strip])Strip whitespace (including newlines) from each string in the Series/Index from left side.
Series.str.normalize(form)Return the Unicode normal form for the strings in the Series/Index.
Series.str.pad(width[, side, fillchar])Pad strings in the Series/Index with an additional character to specified side.
Series.str.partition([pat, expand])Split the string at the first occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
Series.str.repeat(repeats)Duplicate each string in the Series/Index by indicated number of times.
Series.str.replace(pat, repl[, n, case, flags])替换
Series.str.rfind(sub[, start, end])Return highest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
Series.str.rindex(sub[, start, end])Return highest indexes in each strings where the substring is fully contained between [start:end].
Series.str.rjust(width[, fillchar])Filling left side of strings in the Series/Index with an additional character.
Series.str.rpartition([pat, expand])Split the string at the last occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
Series.str.rstrip([to_strip])Strip whitespace (including newlines) from each string in the Series/Index from right side.
Series.str.slice([start, stop, step])Slice substrings from each element in the Series/Index
Series.str.slice_replace([start, stop, repl])Replace a slice of each string in the Series/Index with another string.
Series.str.split([pat, n, expand])分割字符串
Series.str.rsplit([pat, n, expand])从右边分割字符串
Series.str.startswith(pat[, na])是否以…开头
Series.str.strip([to_strip])去两边的空白
Series.str.swapcase()大小写翻转
Series.str.title()首字母大写
Series.str.translate(table[, deletechars])根据映射表翻译
Series.str.upper()全部大写
Series.str.wrap(width, **kwargs)Wrap long strings in the Series/Index to be formatted in paragraphs with length less than a given width.
Series.str.zfill(width)Filling left side of strings in the Series/Index with 0.
Series.str.isalnum()是否是个数字
Series.str.isalpha()是否是个字母
Series.str.isdigit()Check whether all characters in each string in the Series/Index are digits.
Series.str.isspace()是否是空白
Series.str.islower()是否是小写
Series.str.isupper()是否是大学
Series.str.istitle()首字母大写
Series.str.isnumeric()数字
Series.str.isdecimal()小数
Series.str.get_dummies([sep])Split each string in the Series by sep and return a frame of dummy/indicator variables.

分类

方法描述
Series.cat.categoriesThe categories of this categorical.
Series.cat.orderedGets the ordered attribute
Series.cat.codes
Series.cat.rename_categories(*args, **kwargs)Renames categories.
Series.cat.reorder_categories(*args, **kwargs)Reorders categories as specified in new_categories.
Series.cat.add_categories(*args, **kwargs)Add new categories.
Series.cat.remove_categories(*args, **kwargs)Removes the specified categories.
Series.cat.remove_unused_categories(*args, …)Removes categories which are not used.
Series.cat.set_categories(*args, **kwargs)Sets the categories to the specified new_categories.
Series.cat.as_ordered(*args, **kwargs)Sets the Categorical to be ordered
Series.cat.as_unordered(*args, **kwargs)Sets the Categorical to be unordered
Categorical(values[, categories, ordered, …])Represents a categorical variable in classic R / S-plus fashion
Categorical.from_codes(codes, categories[, …])Make a Categorical type from codes and categories arrays.

作图

方法描述
Series.plot([kind, ax, figsize, ….])Series plotting accessor and method
Series.plot.area(**kwds)面积图Area plot
Series.plot.bar(**kwds)垂直条形图Vertical bar plot
Series.plot.barh(**kwds)水平条形图Horizontal bar plot
Series.plot.box(**kwds)箱图Boxplot
Series.plot.density(**kwds)核密度Kernel Density Estimate plot
Series.plot.hist([bins])直方图Histogram
Series.plot.kde(**kwds)核密度Kernel Density Estimate plot
Series.plot.line(**kwds)线图Line plot
Series.plot.pie(**kwds)饼图Pie chart
Series.hist([by, ax, grid, xlabelsize, …])Draw histogram of the input series using matplotlib

转化为其他格式

方法描述
Series.from_csv(path[, sep, parse_dates, …])Read CSV file (DEPRECATED, please use pandas.read_csv()instead).
Series.to_pickle(path[, compression, protocol])Pickle (serialize) object to input file path.
Series.to_csv([path, index, sep, na_rep, …])Write Series to a comma-separated values (csv) file
Series.to_dict([into])Convert Series to {label -> value} dict or dict-like object.
Series.to_excel(excel_writer[, sheet_name, …])Write Series to an excel sheet
Series.to_frame([name])Convert Series to DataFrame
Series.to_xarray()Return an xarray object from the pandas object.
Series.to_hdf(path_or_buf, key, **kwargs)Write the contained data to an HDF5 file using HDFStore.
Series.to_sql(name, con[, flavor, schema, …])Write records stored in a DataFrame to a SQL database.
Series.to_msgpack([path_or_buf, encoding])msgpack (serialize) object to input file path
Series.to_json([path_or_buf, orient, …])Convert the object to a JSON string.
Series.to_sparse([kind, fill_value])Convert Series to SparseSeries
Series.to_dense()Return dense representation of NDFrame (as opposed to sparse)
Series.to_string([buf, na_rep, …])Render a string representation of the Series
Series.to_clipboard([excel, sep])Attempt to write text representation of object to the system clipboard This can be pasted into Excel, for example.
Series.to_latex([buf, columns, col_space, …])Render an object to a tabular environment table.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值