options
Options and settingsOverviewpandas has an options system that lets you customize some aspects of its behaviour,display-related options being those the user is most likely to adjust. Options have a full “dotted-style”, case-insensitive name (e.g. display.max_rows).You can get/set options directly as attributes of the top-level options attribute: 123456789In [1]: import pandas as pdIn [2]: pd.options.display.max_rowsOut[2]: 15In [3]: pd.options.display.max_rows = 999In [4]: pd.options.disp...
reshaping
Reshaping and pivot tablesReshaping by pivoting DataFrame objects Data is often stored in so-called “stacked” or “record” format: 123456789101112131415In [1]: dfOut[1]: date variable value0 2000-01-03 A 0.4691121 2000-01-04 A -0.2828632 2000-01-05 A -1.5090593 2000-01-03 B -1.1356324 2000-01-04 B 1.2121125 2000-01-05 B -0.1732156 2000-01-03 C 0.1192097 2000-01-04 C -1.0442368 2000-01-05 C -0.8618499 2000-...
style
StylingNew in version 0.17.1 Provisional: This is a new feature and still under development. We’ll be adding features and possibly making breaking changes in future releases. We’d love to hear your feedback. This document is written as a Jupyter Notebook, and can be viewed or downloaded here. You can apply conditional formatting, the visual styling of a DataFrame depending on the data within, by using the DataFrame.style property. This is a property that returns a Styler object, which has use...
sparse
Sparse data structures::: tip Note SparseSeries and SparseDataFrame have been deprecated. Their purposeis served equally well by a Series or DataFrame withsparse values. See Migrating for tips on migrating. ::: Pandas provides data structures for efficiently storing sparse data.These are not necessarily sparse in the typical “mostly 0”. Rather, you can view theseobjects as being “compressed” where any data matching a specific value (NaN / missing value, though any valuecan be chosen, inc...
timedeltas
时间差Timedelta,时间差,即时间之间的差异,用 日、时、分、秒 等时间单位表示,时间单位可为正,也可为负。 Timedelta 是 datetime.timedelta 的子类,两者的操作方式相似,但 Timedelta 兼容 np.timedelta64 等数据类型,还支持自定义表示形式、能解析多种类型的数据,并支持自有属性。 解析数据,生成时间差Timedelta() 支持用多种参数生成时间差: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849In [1]: import datetime# 字符串In [2]: pd.Timedelta('1 days')Out[2]: Timedelta('1 days 00:00:00')In [3]: pd.Timedelta('1 days 00:00:00')Out[3]: Timedelta('1 days 00:00:00...
text
Pandas 处理文本字符串序列和索引包含一些列的字符操作方法,这可以使我们轻易操作数组中的各个元素。最重要的是,这些方法可以自动跳过 缺失/NA 值。这些方法可以在str属性中访问到,并且基本上和python内建的(标量)字符串方法同名: 12345678910111213141516171819202122232425262728293031323334353637383940In [1]: s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])In [2]: s.str.lower()Out[2]: 0 a1 b2 c3 aaba4 baca5 NaN6 caba7 dog8 catdtype: objectIn [3]: s.str...
timeseries
时间序列与日期用法依托 NumPy 的 datetime64、timedelta64 等数据类型,pandas 可以处理各种时间序列数据,还能调用 scikits.timeseries 等 Python 支持库的时间序列功能。 Pandas 支持以下操作: 解析时间格式字符串、np.datetime64、datetime.datetime 等多种时间序列数据。 12345678In [1]: import datetimeIn [2]: dti = pd.to_datetime(['1/1/2018', np.datetime64('2018-01-01'), ...: datetime.datetime(2018, 1, 1)]) ...: In [3]: dtiOut[3]: DatetimeIndex(['2018-01-01', '2018-01-01', '2018-01-01'], dtype='dateti...
visualization
VisualizationWe use the standard convention for referencing the matplotlib API: 123In [1]: import matplotlib.pyplot as pltIn [2]: plt.close('all') We provide the basics in pandas to easily create decent looking plots.See the ecosystem section for visualizationlibraries that go beyond the basics documented here. ::: tip Note All calls to np.random are seeded with 123456. ::: Basic plotting: plotWe will demonstrate the basics, see the cookbook forsome advanced strategies. The plot me...
animated_histogram
动画直方图使用路径补丁为动画直方图绘制一堆矩形。 1234567891011121314151617181920import numpy as npimport matplotlib.pyplot as pltimport matplotlib.patches as patchesimport matplotlib.path as pathimport matplotlib.animation as animation# Fixing random state for reproducibilitynp.random.seed(19680801)# histogram our data with numpydata = np.random.randn(1000)n, bins = np.histogram(data, 100)# get the corners of the rectangles for the histogramleft = np.array(bins[:-1])right = np.array(bins[1:])bottom = np.zeros(len(le...
animate_decay
衰变这个例子展示了: 使用生成器来驱动动画, 在动画期间更改轴限制。 1234567891011121314151617181920212223242526272829303132333435363738394041424344import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animationdef data_gen(t=0): cnt = 0 while cnt < 1000: cnt += 1 t += 0.1 yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)def init(): ax.set_ylim(-1.1, 1.1) ax.set_xlim(0, 10) del xdata[:] del ydata[:] line.set_data(xdata, ydata) return line,fig, ax = plt.sub...














