content
large_stringlengths
3
20.5k
url
large_stringlengths
54
193
branch
large_stringclasses
4 values
source
large_stringclasses
42 values
embeddings
listlengths
384
384
score
float64
-0.21
0.65
the sought labels are in fact present: .. ipython:: python s[s.index.isin([2, 4, 6])] # compare it to the following s.reindex([2, 4, 6]) In addition to that, ``MultiIndex`` allows selecting a separate level to use in the membership check: .. ipython:: python s\_mi = pd.Series(np.arange(6), index=pd.MultiIndex.from\_pro...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ 0.0016554888570681214, -0.05420451611280441, -0.03636747971177101, -0.02975904941558838, 0.0832367017865181, -0.0049860491417348385, 0.06128903850913048, -0.011533736251294613, -0.03273067995905876, -0.061335157603025436, -0.003505971748381853, -0.029537983238697052, 0.017334293574094772, ...
0.069592
accept ``axis`` and ``level`` parameters to align the input when performing the ``where``. .. ipython:: python df2 = df.copy() df2.where(df2 > 0, df2['A'], axis='index') This is equivalent to (but faster than) the following. .. ipython:: python df2 = df.copy() df.apply(lambda x, y: x.where(x > 0, y), y=df['A']) ``where...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ -0.05125946179032326, -0.07139718532562256, -0.030055804178118706, -0.06173822283744812, 0.036068230867385864, -0.011898120865225792, -0.0035899977665394545, -0.08447405695915222, -0.0028085983358323574, 0.052990589290857315, 0.06800760328769684, 0.04607872664928436, -0.06539958715438843, ...
-0.081473
if they were columns in the frame: .. ipython:: python n = 10 colors = np.random.choice(['red', 'green'], size=n) foods = np.random.choice(['eggs', 'ham'], size=n) colors foods index = pd.MultiIndex.from\_arrays([colors, foods], names=['color', 'food']) df = pd.DataFrame(np.random.randn(n, 2), index=index) df df.query(...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ 0.0650913342833519, -0.029626937583088875, -0.007325637619942427, 0.022835297510027885, 0.05290833115577698, -0.01980762556195259, 0.07352018356323242, -0.052668385207653046, 0.043639056384563446, -0.05739165470004082, 0.020525788888335228, -0.022508522495627403, -0.020551204681396484, -0....
-0.019525
3), columns=list('abc')) df['bools'] = np.random.rand(len(df)) > 0.5 df.query('~bools') df.query('not bools') df.query('not bools') == df[~df['bools']] Of course, expressions can be arbitrarily complex too: .. ipython:: python # short query syntax shorter = df.query('a < b < c and (not bools) or bools > 2') # equivalen...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ 0.12642095983028412, 0.03827521950006485, -0.00010375498095527291, -0.006989301182329655, 0.07968663424253464, -0.06457372009754181, 0.020028989762067795, -0.10535204410552979, 0.023819660767912865, 0.03575998917222023, 0.005966408643871546, 0.011233038268983364, 0.020901428535580635, -0.0...
-0.064307
1.2.0 and removed in version 2.0.0. .. \_indexing.class: Index objects ------------- The pandas :class:`~pandas.Index` class and its subclasses can be viewed as implementing an \*ordered multiset\*. Duplicates are allowed. :class:`~pandas.Index` also provides the infrastructure necessary for lookups, data alignment, an...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ -0.06503331661224365, -0.01722729206085205, 0.04126555845141411, -0.029798196628689766, 0.009996479377150536, -0.04714972898364067, 0.017239537090063095, -0.0696616843342781, -0.045064568519592285, 0.011817297898232937, -0.007153842132538557, 0.05752410739660263, -0.03785181790590286, -0.0...
0.009253
takes a column name (for a regular ``Index``) or a list of column names (for a ``MultiIndex``). To create a new, re-indexed DataFrame: .. ipython:: python data = pd.DataFrame({'a': ['bar', 'bar', 'foo', 'foo'], 'b': ['one', 'two', 'one', 'two'], 'c': ['z', 'y', 'x', 'w'], 'd': [1., 2., 3, 4]}) data indexed1 = data.set\...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/indexing.rst
main
pandas
[ 0.011549956165254116, -0.06792714446783066, 0.005978629924356937, 0.022744234651327133, 0.019105829298496246, -0.030605558305978775, 0.02353350818157196, -0.06532762944698334, -0.027836233377456665, 0.01226762868463993, 0.02510945312678814, 0.05143008381128311, -0.047756537795066833, -0.02...
-0.038272
.. \_10min: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 10 minutes to pandas \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* This is a short introduction to pandas, geared mainly for new users. You can see more complex recipes in the :ref:`Cookbook`. Customarily, we import as follows: .. ipython:: python import nump...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/10min.rst
main
pandas
[ -0.039072416722774506, 0.03811987116932869, -0.023016618564724922, 0.006863722577691078, 0.029783833771944046, -0.050650421530008316, -0.017872512340545654, -0.02736865170300007, -0.027857979759573936, -0.04915979877114296, 0.011971313506364822, -0.00505433464422822, -0.1024940237402916, -...
0.109702
column and yields a :class:`Series`: .. ipython:: python df["A"] If the label only contains letters, numbers, and underscores, you can alternatively use the column name attribute: .. ipython:: python df.A Passing a list of column labels selects multiple columns, which can be useful for getting a subset/rearranging: .. ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/10min.rst
main
pandas
[ -0.006034628953784704, -0.010262607596814632, 0.011872749775648117, -0.03679299354553223, 0.0985039621591568, 0.05954020842909813, 0.04868039861321449, -0.057661022990942, 0.02016243152320385, -0.012127515859901905, 0.023170841857790947, 0.029646465554833412, -0.10085888206958771, -0.06581...
-0.055539
with the union of the index or column labels. In addition, pandas automatically broadcasts along the specified dimension and will fill unaligned labels with ``np.nan``. .. ipython:: python s = pd.Series([1, 3, 5, np.nan, 6, 8], index=dates).shift(2) s df.sub(s, axis="index") User defined functions ~~~~~~~~~~~~~~~~~~~~~...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/10min.rst
main
pandas
[ -0.011624880135059357, -0.048470668494701385, -0.04074970632791519, -0.028264351189136505, 0.025985538959503174, -0.015712497755885124, -0.01601712591946125, 0.006888986565172672, 0.028875427320599556, -0.013030105270445347, 0.018199963495135307, -0.020713793113827705, -0.03216486796736717, ...
0.039258
stacked.unstack(0) Pivot tables ~~~~~~~~~~~~ See the section on :ref:`Pivot Tables `. .. ipython:: python df = pd.DataFrame( { "A": ["one", "one", "two", "three"] \* 3, "B": ["A", "B", "C"] \* 4, "C": ["foo", "foo", "foo", "bar", "bar", "bar"] \* 2, "D": np.random.randn(12), "E": np.random.randn(12), } ) df :func:`pivo...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/10min.rst
main
pandas
[ -0.05046761780977249, -0.08483775705099106, -0.0037058915477246046, -0.05333909019827843, -0.04498845711350441, 0.010370365343987942, -0.03689506649971008, -0.03548106923699379, 0.00564960390329361, 0.05642210692167282, 0.02835080772638321, 0.004583247471600771, -0.06605616956949234, -0.03...
-0.063888
a boolean operation on a :class:`Series` or :class:`DataFrame` you might see an exception like: .. ipython:: python :okexcept: if pd.Series([False, True, False]): print("I was true") See :ref:`Comparisons` and :ref:`Gotchas` for an explanation and what to do.
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/10min.rst
main
pandas
[ 0.0050897784531116486, 0.002139586489647627, -0.0305392574518919, 0.01031460054218769, 0.047556377947330475, -0.0662662461400032, -0.00952934194356203, -0.05918833240866661, 0.02676086686551571, 0.013734400272369385, 0.07145142555236816, 0.016166727989912033, -0.061096176505088806, -0.0404...
-0.01268
.. \_window: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Windowing operations \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* pandas contains a compact set of APIs for performing windowing operations - an operation that performs an aggregation over a sliding partition of values. The API functions similarly to the ``...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ -0.06602593511343002, -0.005893649533390999, 0.01684991642832756, 0.00706711458042264, 0.009015283547341824, -0.012411811389029026, -0.001013501430861652, -0.03090721182525158, 0.03181915357708931, -0.03815891966223717, -0.051760077476501465, -0.001509509515017271, -0.04833871126174927, -0...
0.022627
a windowing object which returns a new object that supports passing in new :class:`DataFrame` or :class:`Series` objects to continue the windowing calculation with the new values (i.e. online calculations). The methods on this new windowing objects must call the aggregation method first to "prime" the initial state of ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ 0.011595726944506168, -0.027895718812942505, -0.017401644960045815, -0.0016273696674034, -0.012562301941215992, -0.06440012902021408, -0.017383407801389694, -0.008260700851678848, 0.02956487238407135, 0.037817128002643585, -0.009392149746418, 0.014615335501730442, -0.07862997055053711, -0....
0.026545
passed to ``get\_window\_bounds`` and the defined method must always accept these arguments. For example, if we have the following :class:`DataFrame` .. ipython:: python use\_expanding = [True, False, True, False, True] use\_expanding df = pd.DataFrame({"values": range(5)}) df and we want to use an expanding window whe...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ 0.024427300319075584, -0.009692540392279625, -0.00548087852075696, 0.013146516866981983, 0.0383317805826664, -0.052117541432380676, 0.01587602309882641, 0.047777850180864334, 0.002879821229726076, -0.029818957671523094, -0.07112500071525574, 0.02798936888575554, -0.07730690389871597, -0.00...
0.03443
two :class:`Series` or any combination of :class:`DataFrame`/:class:`Series` or :class:`DataFrame`/:class:`DataFrame`. Here is the behavior in each case: \* two :class:`Series`: compute the statistic for the pairing. \* :class:`DataFrame`/:class:`Series`: compute the statistics for each column of the DataFrame with the...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ -0.05868670716881752, -0.03231772780418396, -0.05699615925550461, 0.0006774468347430229, 0.039392467588186264, -0.010588286444544792, -0.062043119221925735, -0.04963463544845581, -0.0008494480280205607, -0.00001820910256356001, 0.025370076298713684, 0.00242114020511508, -0.07309292256832123,...
-0.00629
= \frac{x\_t + (1 - \alpha)x\_{t-1} + (1 - \alpha)^2 x\_{t-2} + ... + (1 - \alpha)^t x\_{0}}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} When ``adjust=False`` is specified, moving averages are calculated as .. math:: y\_0 &= x\_0 \\ y\_t &= (1 - \alpha) y\_{t-1} + \alpha x\_t, which is equivalent to using...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ -0.0505092516541481, -0.07289119064807892, 0.017111102119088173, 0.01668676920235157, 0.0030924957245588303, -0.08125518262386322, 0.02754509076476097, 0.012691257521510124, 0.036315035074949265, 0.026452602818608284, -0.01853332854807377, -0.025222470983862877, 0.0374581515789032, -0.0197...
0.127642
math:: y\_t = \frac{\sum\_{i=0}^t 0.5^\frac{t\_{t} - t\_{i}}{\lambda} x\_{t-i}}{\sum\_{i=0}^t 0.5^\frac{t\_{t} - t\_{i}}{\lambda}}, ExponentialMovingWindow also has an ``ignore\_na`` argument, which determines how intermediate null values affect the calculation of the weights. When ``ignore\_na=False`` (the default), w...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/window.rst
main
pandas
[ -0.08641219139099121, -0.032428331673145294, 0.006065193563699722, 0.01785438135266304, -0.044632043689489365, -0.10676004737615585, 0.04455564171075821, -0.030674783512949944, 0.10208158940076828, 0.029732530936598778, 0.028662875294685364, -0.10966519266366959, 0.025032540783286095, -0.0...
0.046906
.. \_copy\_on\_write: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Copy-on-Write (CoW) \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* .. note:: Copy-on-Write is now the default with pandas 3.0. Copy-on-Write was first introduced in version 1.5.0. Starting from version 2.0 most of the optimizations that become possible t...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/copy_on_write.rst
main
pandas
[ -0.10796095430850983, -0.0672023668885231, -0.0028746367897838354, 0.06849268078804016, 0.05939752981066704, -0.09663162380456924, -0.013459697365760803, -0.03635954484343529, 0.013637866824865341, 0.036648645997047424, 0.031208358705043793, 0.06531418859958649, -0.07050485163927078, -0.04...
0.054475
subset = df["foo"] In [3]: subset.iloc[0] = 100 In [4]: df Out[4]: foo bar 0 100 4 1 2 5 2 3 6 This is not possible anymore with CoW, since the CoW rules explicitly forbid this. This includes updating a single column as a :class:`Series` and relying on the change propagating back to the parent :class:`DataFrame`. This ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/copy_on_write.rst
main
pandas
[ -0.04368839040398598, -0.031684041023254395, 0.05005083605647087, -0.004344531334936619, 0.07014593482017517, -0.09430232644081116, 0.02274293825030327, -0.03411836922168732, -0.0032696512062102556, 0.05951034277677536, 0.03894568234682083, 0.03934456408023834, -0.09152857214212418, -0.064...
-0.013953
2, 3], "bar": [4, 5, 6]}) In [2]: subset = df["foo"] In [3]: subset.iloc[0] = 100 In [4]: df Out[4]: foo bar 0 100 4 1 2 5 2 3 6 CoW triggers a copy when ``df`` is changed to avoid mutating ``view`` as well: .. ipython:: python df = pd.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]}) view = df[:] df.iloc[0, 0] = 100 df ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/copy_on_write.rst
main
pandas
[ -0.05200863629579544, -0.07729106396436691, 0.016420286148786545, -0.026862556114792824, 0.053402114659547806, -0.0823536068201065, 0.07056305557489395, -0.08721432089805603, 0.024657946079969406, 0.03506390377879143, 0.058410633355379105, 0.023647110909223557, -0.06869429349899292, -0.041...
0.004716
shares data with another object. This mechanism was added to methods that don't require a copy of the underlying data. Popular examples are :meth:`DataFrame.drop` for ``axis=1`` and :meth:`DataFrame.rename`. These methods return views when Copy-on-Write is enabled, which provides a significant performance improvement c...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/copy_on_write.rst
main
pandas
[ -0.052496954798698425, -0.0486476756632328, -0.09651321917772293, 0.04113993048667908, 0.03818260505795479, -0.10737387090921402, -0.006038382649421692, -0.0014132866635918617, 0.08900201320648193, 0.04293196648359299, 0.08850834518671036, 0.10899423807859421, -0.04519904777407646, -0.0250...
0.159689
.. \_categorical: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Categorical data \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* This is an introduction to pandas categorical data type, including a short comparison with R's ``factor``. ``Categoricals`` are a pandas data type corresponding to categorical variables in statistics. A cat...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.11184284090995789, -0.017168737947940826, 0.005089474841952324, -0.021828802302479744, -0.003682393115013838, -0.015087543986737728, -0.06810551136732101, -0.027631592005491257, -0.032299164682626724, 0.004035427700728178, 0.05289723351597786, -0.01314298715442419, -0.06368952244520187, ...
-0.030476
list("abca"), "B": list("bccd")}) df\_cat = df.astype("category") df\_cat.dtypes This conversion is likewise done column by column: .. ipython:: python df\_cat["A"] df\_cat["B"] Controlling behavior ~~~~~~~~~~~~~~~~~~~~ In the examples above where we passed ``dtype='category'``, we used the default behavior: 1. Categor...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.028487108647823334, -0.024740062654018402, -0.022768860682845116, 0.0007192306802608073, -0.03468727692961693, -0.002154566580429673, -0.00036070492933504283, -0.038365501910448074, 0.0008990662754513323, 0.02397785894572735, 0.018979037180542946, -0.03886937350034714, -0.05705601349472999...
-0.030533
pd.Categorical(np.array([], dtype=float)) c2.dtype == c3.dtype Description ----------- Using :meth:`~DataFrame.describe` on categorical data will produce similar output to a ``Series`` or ``DataFrame`` of type ``string``. .. ipython:: python cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"]) df =...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.07702284306287766, -0.03490464389324188, 0.0031127771362662315, -0.02971239760518074, -0.015020141378045082, -0.005386494565755129, -0.051331132650375366, -0.05060378462076187, 0.026028551161289215, -0.012470290996134281, 0.02817354165017605, -0.03440989926457405, -0.09999168664216995, 0...
-0.039967
"b", "c", "a"]).astype(CategoricalDtype(ordered=True)) s = s.sort\_values() s s.min(), s.max() You can set categorical data to be ordered by using ``as\_ordered()`` or unordered by using ``as\_unordered()``. These will by default return a \*new\* object. .. ipython:: python s.cat.as\_ordered() s.cat.as\_unordered() Sor...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.0735524594783783, -0.022468212991952896, 0.02517368271946907, -0.0055139255709946156, -0.11403229087591171, 0.01920107565820217, -0.03207538276910782, -0.021280210465192795, -0.0042306846007704735, 0.004477234091609716, 0.00458992924541235, 0.05427204445004463, -0.03162084519863129, -0.0...
-0.023485
.. ipython:: python cat == cat\_base cat == np.array([1, 2, 3]) cat == 2 This doesn't work because the categories are not the same: .. ipython:: python try: cat > cat\_base2 except TypeError as e: print("TypeError:", str(e)) If you want to do a "non-equality" comparison of a categorical series with a list-like object w...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.07704579085111618, 0.008073161356151104, 0.03869534656405449, 0.014197616837918758, -0.024914219975471497, -0.048557110130786896, -0.07086225599050522, -0.05596843734383583, 0.009656133130192757, -0.021197447553277016, -0.01021772250533104, -0.007985199801623821, -0.06408286839723587, -0...
-0.008343
``s.cat.categories`` are of an appropriate type: .. ipython:: python str\_s = pd.Series(list("aabb")) str\_cat = str\_s.astype("category") str\_cat str\_cat.str.contains("a") date\_s = pd.Series(pd.date\_range("1/1/2015", periods=5)) date\_cat = date\_s.astype("category") date\_cat date\_cat.dt.day .. note:: The return...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ -0.00439746817573905, 0.024623636156320572, -0.008438668213784695, 0.08916947990655899, -0.06665738672018051, -0.028002159669995308, -0.0367930643260479, -0.013861417770385742, 0.014434338547289371, -0.04986068978905678, 0.04285794124007225, -0.006550318095833063, -0.10946647822856903, -0....
-0.042898
:func:`~pandas.api.types.union\_categoricals` function will combine a list-like of categoricals. The new categories will be the union of the categories being combined. .. ipython:: python from pandas.api.types import union\_categoricals a = pd.Categorical(["b", "c"]) b = pd.Categorical(["a", "b"]) union\_categoricals([...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.09710468351840973, -0.020727066323161125, 0.018219035118818283, 0.007520295213907957, -0.055081941187381744, 0.006617137696594, -0.04558086395263672, -0.02598920278251171, -0.05346309393644333, 0.03906301409006119, 0.011901769787073135, 0.038621556013822556, -0.08427871018648148, 0.01722...
-0.060955
only two categories s s.cat.codes Methods for working with missing data, e.g. :meth:`~Series.isna`, :meth:`~Series.fillna`, :meth:`~Series.dropna`, all work normally: .. ipython:: python s = pd.Series(["a", "b", np.nan], dtype="category") s pd.isna(s) s.fillna("a") Differences to R's ``factor`` ------------------------...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ -0.008076272904872894, -0.045571520924568176, -0.059153370559215546, 0.026960201561450958, -0.03251784294843674, -0.03720870614051819, -0.06755388528108597, -0.014713477343320847, -0.020642146468162537, -0.03305082768201828, 0.09569987654685974, -0.07624424993991852, -0.03764795884490013, ...
-0.013385
:ref:`advanced indexing docs ` for a more detailed explanation. Setting the index will create a ``CategoricalIndex``: .. ipython:: python cats = pd.Categorical([1, 2, 3, 4], categories=[4, 2, 3, 1]) strings = ["a", "b", "c", "d"] values = [4, 2, 3, 1] df = pd.DataFrame({"strings": strings, "values": values}, index=cats...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/categorical.rst
main
pandas
[ 0.06479023396968842, -0.028950432315468788, 0.04869658499956131, -0.013134501874446869, -0.005228627473115921, 0.017912909388542175, -0.05062359198927879, -0.036596111953258514, 0.012139266356825829, 0.009315102361142635, 0.026447655633091927, 0.12324924021959305, -0.09846794605255127, -0....
-0.046244
.. \_timedeltas: {{ header }} .. \_timedeltas.timedeltas: \*\*\*\*\*\*\*\*\*\*\* Time deltas \*\*\*\*\*\*\*\*\*\*\* Timedeltas are differences in times, expressed in difference units, e.g. days, hours, minutes, seconds. They can be both positive and negative. ``Timedelta`` is a subclass of ``datetime.timedelta``, and b...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timedeltas.rst
main
pandas
[ -0.03636625036597252, 0.06612656265497208, 0.011109145358204842, 0.0004634090873878449, -0.07308696955442429, -0.0808635726571083, -0.04328274354338646, 0.01659356988966465, -0.019953018054366112, -0.02710762619972229, 0.028002876788377762, -0.09803729504346848, -0.0472998209297657, 0.0465...
0.050614
df.idxmin() df.idxmax() ``min, max, idxmin, idxmax`` operations are supported on Series as well. A scalar result will be a ``Timedelta``. .. ipython:: python df.min().max() df.min(axis=1).min() df.min().idxmax() df.min(axis=1).idxmin() You can fillna on timedeltas, passing a timedelta to get a particular value. .. ipyt...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timedeltas.rst
main
pandas
[ -0.012667432427406311, -0.0323338508605957, -0.02185577154159546, -0.029507538303732872, -0.00936761125922203, -0.045751772820949554, 0.029036616906523705, -0.0003207503177691251, -0.026275504380464554, -0.02237837016582489, 0.037834472954273224, -0.009282401762902737, -0.02004207856953144, ...
0.02353
objects. Passing ``np.nan/pd.NaT/nat`` will represent missing values. .. ipython:: python pd.TimedeltaIndex( [ "1 days", "1 days, 00:00:05", np.timedelta64(2, "D"), datetime.timedelta(days=2, seconds=2), ] ) The string 'infer' can be passed in order to set the frequency of the index as the inferred frequency upon creat...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timedeltas.rst
main
pandas
[ -0.02072705328464508, 0.025747740641236305, 0.002182889264076948, 0.08816598355770111, -0.008657003752887249, -0.0481199249625206, -0.0055394782684743404, -0.031548041850328445, -0.025083433836698532, -0.02729794941842556, -0.00001735218393150717, -0.11471773684024811, -0.0979500487446785, ...
0.067435
.. \_groupby: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Group by: split-apply-combine \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* By "group by" we are referring to a process involving one or more of the following steps: \* \*\*Splitting\*\* the data into groups based on some...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.09756170958280563, 0.0678657740354538, 0.05675816163420677, -0.00480273924767971, 0.030689597129821777, -0.03677699342370033, 0.02737935446202755, -0.02373816817998886, -0.050455186516046524, 0.06206720694899559, 0.02471129409968853, -0.1066511869430542, 0.046640023589134216, -0.0858262...
0.051447
``groupby`` may refer to either a column or an index level. If a string matches both a column name and an index level name, a ``ValueError`` will be raised. .. ipython:: python df = pd.DataFrame( { "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], "B": ["one", "one", "two", "three", "two", "two", "one", "t...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.03481816127896309, -0.04891614243388176, -0.014742327854037285, 0.02482827939093113, 0.061110761016607285, -0.04492532089352608, 0.011844991706311703, -0.0513358935713768, 0.034090831875801086, -0.0018043762538582087, 0.04657064005732536, -0.026630550622940063, -0.02886732667684555, -0....
-0.041683
function on the GroupBy object returns the number of groups, which is the same as the length of the ``groups`` dictionary: .. ipython:: python grouped = df.groupby(["A", "B"]) grouped.groups len(grouped) .. \_groupby.tabcompletion: ``GroupBy`` will tab complete column names, GroupBy operations, and other attributes: .....
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.07601841539144516, -0.008362841792404652, 0.008738785982131958, 0.04167131334543228, 0.007803856395184994, -0.03561950847506523, 0.0511246956884861, -0.09501758217811584, -0.05815127119421959, 0.02630784548819065, 0.04184753820300102, -0.03373394161462784, -0.09065525978803635, -0.026009...
-0.069936
this method avoids recomputing the internal grouping information derived from the passed key. You can also include the grouping columns if you want to operate on them. .. ipython:: python grouped[["A", "B"]].sum() .. note:: The ``groupby`` operation in pandas drops the ``name`` field of the columns Index object after t...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.008011377416551113, 0.011403840035200119, -0.04930233582854271, 0.01092320866882801, 0.034705691039562225, -0.04191877320408821, 0.05743764340877533, -0.06698337197303772, -0.0004988310975022614, 0.0001138566731242463, 0.059445373713970184, 0.007826399989426136, -0.06127103045582771, -0....
-0.037722
values are the sizes of each group. .. ipython:: python grouped = df.groupby(["A", "B"]) grouped.size() While the :meth:`.DataFrameGroupBy.describe` method is not itself a reducer, it can be used to conveniently produce a collection of summary statistics about each of the groups. .. ipython:: python grouped.describe() ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.06518430262804031, -0.027181357145309448, -0.011806491762399673, -0.0020476041827350855, 0.008978188037872314, -0.0021259780041873455, -0.014743109233677387, -0.0000729596649762243, 0.04696819186210632, -0.03198011964559555, 0.015156585723161697, -0.015496307983994484, -0.02094845473766327...
-0.032398
"std": "baz"}) ) Or, you can simply pass a list of tuples each with the name of the new column and the aggregate function: .. ipython:: python ( grouped["C"] .agg([("foo", "sum"), ("bar", "mean"), ("baz", "std")]) ) For a grouped ``DataFrame``, you can rename in a similar manner: By chaining ``rename`` operation, .. ip...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.008434632793068886, -0.012509578838944435, 0.023829497396945953, 0.01936357468366623, -0.09991126507520676, -0.016757696866989136, 0.020483067259192467, 0.01934489794075489, 0.01904255710542202, 0.0024551197420805693, 0.011251838877797127, 0.019695142284035683, -0.062427375465631485, -0...
0.007243
ipython:: python result = speeds.copy() result["cumsum"] = grouped.cumsum() result["diff"] = grouped.diff() result Built-in transformation methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following methods on GroupBy act as transformations. .. csv-table:: :header: "Method", "Description" :widths: 20, 80 :meth:`~.DataFrameGr...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.013076185248792171, -0.00688836770132184, 0.008545187301933765, -0.04625267907977104, -0.051264189183712006, -0.06492793560028076, 0.007506476249545813, 0.02581561915576458, -0.01346807461231947, -0.009663037955760956, -0.00990030076354742, -0.12890766561031342, 0.037112023681402206, -0...
-0.015285
Data grouped = ts.groupby(lambda x: x.year) grouped.mean() grouped.std() # Transformed Data grouped\_trans = transformed.groupby(lambda x: x.year) grouped\_trans.mean() grouped\_trans.std() We can also visually compare the original and transformed data sets. .. ipython:: python compare = pd.DataFrame({"Original": ts, "...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.0007246094755828381, 0.032676275819540024, 0.07424338161945343, -0.0444880835711956, 0.010839168913662434, -0.03260166198015213, -0.05683194845914841, -0.05780225992202759, -0.01029790285974741, -0.009389244019985199, -0.006392586976289749, -0.026804247871041298, -0.005109873134642839, ...
-0.06931
python speeds.groupby("class")[["order", "max\_speed"]].nth(1) Built-in filtrations ~~~~~~~~~~~~~~~~~~~~ The following methods on GroupBy act as filtrations. All these methods have an efficient, GroupBy-specific, implementation. .. csv-table:: :header: "Method", "Description" :widths: 20, 80 :meth:`~.DataFrameGroupBy.h...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.012738014571368694, 0.026300497353076935, 0.012871340848505497, -0.057401832193136215, 0.036986093968153, -0.08143551647663116, 0.038902487605810165, -0.05072960630059242, -0.019743936136364937, 0.014679058454930782, -0.014545805752277374, -0.04789416491985321, -0.005279149394482374, -0....
-0.047696
to :ref:`groupby.aggregate.agg`, the resulting dtype will reflect that of the apply function. If the results from different groups have different dtypes, then a common dtype will be determined in the same way as ``DataFrame`` construction. Control grouped column(s) placement with ``group\_keys`` ~~~~~~~~~~~~~~~~~~~~~~~...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.0374678373336792, -0.07663789391517639, 0.002160086529329419, -0.006175603251904249, 0.029944712296128273, -0.05096554011106491, 0.0555642805993557, -0.04414942488074303, 0.006086545065045357, -0.01340505387634039, 0.03459832817316055, -0.019703634083271027, -0.026719583198428154, -0.07...
-0.014711
end of the result in order. .. ipython:: python days = pd.Categorical( values=["Wed", "Mon", "Thu", "Mon", "Wed", "Sat"], categories=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], ) data = pd.DataFrame( { "day": days, "workers": [3, 4, 1, 4, 2, 2], } ) data data.groupby("day", observed=False, sort=True).sum() data....
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.09045296907424927, 0.027918070554733276, 0.057731229811906815, 0.07408826053142548, -0.02487480454146862, -0.006046043708920479, 0.015484091825783253, -0.0941493883728981, -0.08064422011375427, 0.0076041799038648605, 0.055348627269268036, -0.06920640915632248, -0.09808151423931122, 0.000...
-0.053955
4th, and last date index for each month df.groupby([df.index.year, df.index.month]).nth([0, 3, -1]) You may also use slices or lists of slices. .. ipython:: python df.groupby([df.index.year, df.index.month]).nth[1:] df.groupby([df.index.year, df.index.month]).nth[1:, :-1] Enumerate group items ~~~~~~~~~~~~~~~~~~~~~ To ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ 0.054590895771980286, -0.0491645522415638, -0.001771418610587716, -0.061700109392404556, 0.003955810330808163, 0.050450243055820465, -0.008887720294296741, -0.12813988327980042, 0.006567992735654116, 0.05384470149874687, 0.09352433681488037, 0.007342255208641291, -0.05426887050271034, -0.0...
-0.072683
step in processing, when the relationships between the group rows are more important than their content, or as input to an algorithm which only accepts the integer encoding. (For more information about support in pandas for full categorical data, see the :ref:`Categorical introduction ` and the :ref:`API documentation ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/groupby.rst
main
pandas
[ -0.04933519661426544, -0.06752459704875946, -0.008881226181983948, 0.002544129965826869, 0.009900118224322796, 0.003575447713956237, -0.025892946869134903, -0.0951448604464531, 0.015322022140026093, 0.013302796520292759, -0.007452068384736776, -0.00221350253559649, -0.029426727443933487, -...
-0.005856
.. \_pyarrow: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* PyArrow Functionality \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* pandas can utilize `PyArrow `\_\_ to extend functionality and improve the performance of various APIs. This includes: \* More extensive `data types `\_\_ compared to NumPy \* Missing da...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/pyarrow.rst
main
pandas
[ -0.04204612597823143, -0.0789087563753128, -0.037181638181209564, 0.003319806419312954, 0.004189754836261272, -0.07392565906047821, -0.057185955345630646, -0.0058320979587733746, -0.016948606818914413, -0.023808347061276436, 0.06497949361801147, 0.052375052124261856, -0.05548013001680374, ...
0.010421
provide an ``engine`` keyword that can dispatch to PyArrow to accelerate reading from an IO source. \* :func:`read\_csv` \* :func:`read\_feather` \* :func:`read\_json` \* :func:`read\_orc` \* :func:`read\_parquet` \* :func:`read\_table` (experimental) .. ipython:: python import io data = io.StringIO("""a,b,c 1,2.5,True...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/pyarrow.rst
main
pandas
[ -0.06253670901060104, -0.04468247666954994, -0.0705258846282959, 0.03428532928228378, -0.05111599341034889, -0.11918043345212936, 0.023447757586836815, 0.008862561546266079, -0.03990074247121811, 0.0012441459111869335, 0.03672436252236366, 0.027596384286880493, -0.058418188244104385, -0.02...
0.070254
.. \_enhancingperf: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Enhancing performance \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* In this part of the tutorial, we will investigate how to speed up certain functions operating on pandas :class:`DataFrame` using Cython, Numba and :func:`pandas.eval`. Generally, ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.07469985634088516, -0.0017587871989235282, -0.06465498358011246, -0.05060861259698868, 0.056001633405685425, -0.1041800007224083, -0.01423709001392126, -0.0015941995661705732, -0.02889109216630459, -0.02799566462635994, 0.022744515910744667, -0.011817689053714275, -0.06672563403844833, ...
-0.0185
- a) / N ...: for i in range(N): ...: s += f\_typed(a + i \* dx) ...: return s \* dx ...: .. ipython:: python %timeit df.apply(lambda x: integrate\_f\_typed(x["a"], x["b"], x["N"]), axis=1) Annotating the functions with C types yields an over ten times performance improvement compared to the original Python implementat...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.022362500429153442, -0.02832970581948757, -0.061581142246723175, -0.0148270009085536, -0.01856340281665325, -0.05623573437333107, 0.03131882846355438, -0.014002188108861446, -0.02679225243628025, 0.008106685243546963, -0.04405234381556511, 0.03484020754694939, -0.0312060359865427, 0.015...
0.0778
you to write a pure Python function which can be JIT compiled to native machine instructions, similar in performance to C, C++ and Fortran, by decorating your function with ``@jit``. Numba works by generating optimized machine code using the LLVM compiler infrastructure at import time, runtime, or statically (using the...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.11253536492586136, -0.0200035497546196, -0.036304932087659836, 0.031978730112314224, -0.04521603137254715, -0.14031514525413513, -0.05413547530770302, 0.07598475366830826, 0.01204000785946846, -0.012636834755539894, -0.017778007313609123, 0.02233150228857994, -0.03141510859131813, -0.05...
0.1016
their NumPy array representations with :meth:`Series.to\_numpy`. .. code-block:: python import numba @numba.jit def f\_plain(x): return x \* (x - 1) @numba.jit def integrate\_f\_numba(a, b, N): s = 0 dx = (b - a) / N for i in range(N): s += f\_plain(a + i \* dx) return s \* dx @numba.jit def apply\_integrate\_f\_numba(...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.061447013169527054, -0.0480739027261734, -0.059790778905153275, -0.044723961502313614, -0.03931668773293495, -0.10321467369794846, -0.04475019499659538, 0.009947971440851688, -0.03628125041723251, -0.004291788674890995, -0.04176238551735878, -0.025759130716323853, 0.014460399746894836, ...
0.113753
df3 < df4 or not df\_bool`` \* ``list`` and ``tuple`` literals, e.g., ``[1, 2]`` or ``(1, 2)`` \* Attribute access, e.g., ``df.a`` \* Subscript expressions, e.g., ``df[0]`` \* Simple variable evaluation, e.g., ``pd.eval("df")`` (this is not very useful) \* Math functions: ``sin``, ``cos``, ``exp``, ``log``, ``expm1``, ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ 0.005780424457043409, -0.04504024609923363, -0.024615468457341194, -0.05523938685655594, 0.04198755696415901, -0.07265609502792358, 0.05414189398288727, 0.0018711858429014683, 0.03254358470439911, 0.09994752705097198, 0.06944327801465988, -0.016806310042738914, -0.012290789745748043, 0.053...
0.034439
dependency ``numexpr`` to be installed. The ``'python'`` engine is generally \*not\* useful except for testing other evaluation engines against it. You will achieve \*\*no\*\* performance benefits using :func:`~pandas.eval` with ``engine='python'`` and may incur a performance hit. .. ipython:: python %timeit df1 + df2 ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.04171907156705856, -0.02814994938671589, -0.06817290931940079, -0.034347373992204666, 0.12999041378498077, -0.11170324683189392, -0.002732166787609458, 0.014382743276655674, -0.007050768006592989, -0.027455465868115425, 0.01698671095073223, -0.05271158367395401, -0.05586167424917221, -0...
0.027615
/doc/scripts/eval\_performance.py .. image:: ../\_static/eval-perf.png You will only see the performance benefits of using the ``numexpr`` engine with :func:`pandas.eval` if your :class:`~pandas.DataFrame` has more than approximately 100,000 rows. This plot was created using a :class:`DataFrame` with 3 columns each con...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/enhancingperf.rst
main
pandas
[ -0.02148350328207016, -0.00971473939716816, -0.062642902135849, -0.019789764657616615, 0.13566982746124268, -0.1147516742348671, 0.010161279700696468, 0.02771446667611599, 0.008268234319984913, 0.02484768070280552, 0.005499299615621567, -0.018002033233642578, -0.03153358772397041, 0.002181...
0.069728
.. \_duplicates: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Duplicate Labels \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* :class:`Index` objects are not required to be unique; you can have duplicate row or column labels. This may be a bit confusing at first. If you're familiar with SQL, you know that row labels are similar to a primary key ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/duplicates.rst
main
pandas
[ -0.059295590966939926, -0.047963157296180725, -0.03463078662753105, -0.044337138533592224, -0.019117018207907677, -0.03147793933749199, 0.08349031209945679, -0.06697509437799454, 0.010881812311708927, 0.0027697531040757895, 0.071383535861969, 0.04809528961777687, 0.010428046807646751, -0.0...
0.038918
python df = pd.DataFrame({"A": [0, 1, 2, 3]}, index=["x", "y", "X", "Y"]).set\_flags( allows\_duplicate\_labels=False ) df df.flags.allows\_duplicate\_labels :meth:`DataFrame.set\_flags` can be used to return a new ``DataFrame`` with attributes like ``allows\_duplicate\_labels`` set to some value .. ipython:: python df...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/duplicates.rst
main
pandas
[ 0.04402168095111847, -0.07077963650226593, -0.08713705837726593, -0.017269833013415337, 0.05025206133723259, -0.052411966025829315, 0.03016553819179535, -0.09444579482078552, -0.006562733557075262, -0.014207982458174229, 0.09032337367534637, 0.0285615473985672, -0.05089757218956947, -0.022...
-0.068776
.. \_timeseries: {{ header }} \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Time series / date functionality \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* pandas contains extensive capabilities and features for working with time series data for all domains. Using the NumPy ``dateti...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.07262347638607025, -0.012018483132123947, -0.014740923419594765, -0.001180511200800538, 0.0037016693968325853, -0.055374305695295334, -0.06598176807165146, 0.019346505403518677, 0.0015819198451936245, 0.0053039309568703175, -0.027797160670161247, -0.035285867750644684, -0.1133728176355362...
0.068165
change variables with a time span instead. The span represented by ``Period`` can be specified explicitly, or inferred from datetime string format. For example: .. ipython:: python pd.Period("2011-01") pd.Period("2012-05", freq="D") :class:`Timestamp` and :class:`Period` can serve as an index. Lists of ``Timestamp`` an...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.08015268296003342, -0.0021475895773619413, 0.07485364377498627, 0.06260636448860168, 0.01716238632798195, -0.010406192392110825, 0.02133890613913536, -0.03685287758708, -0.020818786695599556, 0.002367619425058365, -0.03705112636089325, 0.01995147578418255, -0.061763789504766464, 0.00392...
-0.012128
You can pass only the columns that you need to assemble. .. ipython:: python pd.to\_datetime(df[["year", "month", "day"]]) ``pd.to\_datetime`` looks for standard designations of the datetime component in the column names, including: \* required: ``year``, ``month``, ``day`` \* optional: ``hour``, ``minute``, ``second``...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.01958565041422844, 0.028976231813430786, -0.020497648045420647, 0.049858756363391876, 0.013902682811021805, -0.06201210990548134, -0.05941349267959595, 0.04663976654410362, -0.0546654537320137, 0.01478833518922329, 0.02763744443655014, -0.10963508486747742, -0.09045875072479248, -0.0252...
-0.045045
number of timestamps. If we need timestamps on a regular frequency, we can use the :func:`date\_range` and :func:`bdate\_range` functions to create a ``DatetimeIndex``. The default frequency for ``date\_range`` is a \*\*calendar day\*\* while the default for ``bdate\_range`` is a \*\*business day\*\*: .. ipython:: pyth...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ 0.005496602971106768, -0.0004121516540180892, -0.006939128041267395, 0.05707341432571411, -0.04600243270397186, 0.011651739478111267, -0.007561696693301201, 0.010286320000886917, -0.01091443095356226, -0.06185988709330559, -0.010429632849991322, -0.06033552438020706, -0.05012064427137375, ...
0.005783
year and month as strings: .. ipython:: python ts["2011"] ts["2011-6"] This type of slicing will work on a ``DataFrame`` with a ``DatetimeIndex`` as well. Since the partial string selection is a form of label slicing, the endpoints \*\*will be\*\* included. This would include matching times on an included date: .. warn...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.029592880979180336, 0.02122334949672222, 0.04236666113138199, 0.027720240876078606, 0.0795050784945488, -0.0009374485234729946, 0.05069822818040848, 0.009794157929718494, -0.023429591208696365, -0.042216408997774124, 0.013664680533111095, 0.02336655929684639, -0.12042691558599472, -0.01...
0.016542
pd.DatetimeIndex(["2011-12", "2012-01", "2012-02"]) ) series\_monthly.index.resolution series\_monthly["2011-12"] # returns Series Exact indexing ~~~~~~~~~~~~~~ As discussed in previous section, indexing a ``DatetimeIndex`` with a partial string depends on the "accuracy" of the period, in other words how specific the i...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.05309060961008072, 0.020186804234981537, 0.04184567928314209, 0.045013803988695145, 0.03207611292600632, -0.05061737820506096, -0.014438674785196781, 0.053235847502946854, 0.06172870099544525, -0.054830946028232574, -0.02440039813518524, 0.010311664082109928, -0.06035040691494942, 0.010...
0.068582
object and its subclasses. A :class:`DateOffset` is similar to a :class:`Timedelta` that represents a duration of time but follows specific calendar duration rules. For example, a :class:`Timedelta` day will always increment ``datetimes`` by 24 hours, while a :class:`DateOffset` day will increment ``datetimes`` to the ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.06007703021168709, 0.06819447875022888, 0.005631070584058762, 0.009753003716468811, -0.0587572418153286, -0.06644243746995926, -0.04789648950099945, 0.043259624391794205, 0.014602512121200562, -0.014767359010875225, 0.029585156589746475, -0.05223193019628525, -0.010716930963099003, 0.01...
0.097244
+ offset These operations preserve time (hour, minute, etc) information by default. To reset time to midnight, use :meth:`normalize` before or after applying the operation (depending on whether you want the time information included in the operation). .. ipython:: python ts = pd.Timestamp("2014-01-01 09:00") day = pd.o...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.03076980821788311, 0.03067041002213955, -0.007019368000328541, 0.031457651406526566, -0.017124172300100327, -0.07218652963638306, -0.0572657473385334, 0.06629889458417892, -0.03077583573758602, -0.06295569986104965, 0.03623320534825325, -0.034728050231933594, -0.034779831767082214, 0.01...
0.01079
since CustomBusinessDay is a parameterised type, instances of CustomBusinessDay may differ and this is not detectable from the 'C' frequency string. The user therefore needs to ensure that the 'C' frequency string is used consistently within the user's application. .. \_timeseries.businesshour: Business hour ~~~~~~~~~~...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.02459823153913021, 0.07374058663845062, -0.009657499380409718, 0.00512863602489233, -0.0911111906170845, -0.0002576408733148128, 0.013364633545279503, 0.03257690742611885, -0.03628711402416229, -0.07881847023963928, 0.005225014872848988, -0.0873243436217308, -0.042486391961574554, 0.001...
0.018322
USFederalHolidayCalendar bhour\_us = pd.offsets.CustomBusinessHour(calendar=USFederalHolidayCalendar()) # Friday before MLK Day dt = datetime.datetime(2014, 1, 17, 15) dt + bhour\_us # Tuesday after MLK Day (Monday is skipped because it's a holiday) dt + bhour\_us \* 2 You can use keyword arguments supported by either ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.013997389934957027, 0.02133052796125412, 0.019886557012796402, 0.023657502606511116, -0.046464160084724426, 0.016461966559290886, 0.01794460602104664, 0.0026297529693692923, -0.055123619735240936, -0.07018037885427475, -0.0011573946103453636, -0.09028095006942749, -0.06166883185505867, ...
0.015741
"weekly frequency (Mondays)" "W\-TUE", "weekly frequency (Tuesdays)" "W\-WED", "weekly frequency (Wednesdays)" "W\-THU", "weekly frequency (Thursdays)" "W\-FRI", "weekly frequency (Fridays)" "W\-SAT", "weekly frequency (Saturdays)" "(B)Q(E)(S)\-DEC", "quarterly frequency, year ends in December. Same as 'QE'" "(B)Q(E)(S...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ 0.0011489851167425513, 0.023656032979488373, -0.017145775258541107, 0.035429272800683975, -0.09682337939739227, 0.07793828099966049, -0.05415787175297737, -0.036322593688964844, -0.05058314651250839, -0.01254490576684475, 0.04444216564297676, -0.10101303458213806, 0.00926990993320942, -0.0...
0.094571
Saturday to Friday and Sunday to Monday" "before\_nearest\_workday", "apply ``nearest\_workday`` and then move to previous workday before that day" "after\_nearest\_workday", "apply ``nearest\_workday`` and then move to next workday after that day" "sunday\_to\_monday", "move Sunday to following Monday" "next\_monday\_...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.0280319657176733, 0.032169461250305176, 0.05042272433638573, -0.04910753667354584, 0.01661621406674385, -0.01941918209195137, -0.025685667991638184, -0.07640484720468521, -0.07138186693191528, -0.0032765844371169806, 0.011690590530633926, -0.02797211892902851, -0.04769773781299591, 0.07...
0.03548
`. Converting to Python datetimes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``DatetimeIndex`` can be converted to an array of Python native :py:class:`datetime.datetime` objects using the ``to\_pydatetime`` method. .. \_timeseries.resampling: Resampling ---------- pandas has a simple, powerful, and efficient functionality for per...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.049534473568201065, 0.0029559012036770582, -0.0127249239012599, 0.05289386212825775, -0.006840657442808151, -0.12229405343532562, -0.04272899776697159, 0.015879912301898003, 0.01731952093541622, -0.02384706772863865, -0.06171467527747154, 0.010441744700074196, -0.06270615011453629, -0.0...
0.072984
index=rng) If we want to resample to the full range of the series: .. ipython:: python ts.resample("3min").sum() We can instead only resample those groups where we have points as follows: .. ipython:: python from functools import partial from pandas.tseries.frequencies import to\_offset def round(t, freq): # round a Ti...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.07563048601150513, -0.03297293558716774, 0.05656430870294571, 0.03828104957938194, -0.03184368461370468, -0.030637409538030624, -0.004687162581831217, 0.031412653625011444, 0.04333176836371422, -0.034422606229782104, -0.07889424264431, -0.043769292533397675, -0.06423798203468323, -0.037...
0.060677
using ``origin`` with its default value (``'start\_day'``), the result after ``'2000-10-02 00:00:00'`` are not identical depending on the start of time series: .. ipython:: python ts.resample("17min", origin="start\_day").sum() ts[middle:end].resample("17min", origin="start\_day").sum() Here we can see that, when setti...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.08129504323005676, 0.015873992815613747, 0.08958818763494492, 0.004749581217765808, -0.02764696441590786, -0.09654966741800308, -0.015711301937699318, 0.057978108525276184, 0.04260263592004776, -0.028658444061875343, -0.05174781382083893, -0.01367768831551075, -0.09057016670703888, 0.05...
0.006108
python pd.Period("2012", freq="Y-DEC") - pd.Period("2002", freq="Y-DEC") PeriodIndex and period\_range ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Regular sequences of ``Period`` objects can be collected in a ``PeriodIndex``, which can be constructed using the ``period\_range`` convenience function: .. ipython:: python prng = pd.peri...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.05183322727680206, 0.038712337613105774, -0.015604193322360516, -0.010821828618645668, -0.02826547995209694, 0.0245459396392107, -0.049799658358097076, -0.016656531020998955, 0.004880842752754688, -0.05893370509147644, 0.027887333184480667, -0.015561111271381378, -0.02484530583024025, -...
0.029655
common to economics, business, and other fields. Many organizations define quarters relative to the month in which their fiscal year starts and ends. Thus, first quarter of 2011 could start in 2010 or a few months into 2011. Via anchored frequencies, pandas works for all quarterly frequencies ``Q-JAN`` through ``Q-DEC`...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.04495207965373993, -0.010356301441788673, -0.06330370903015137, 0.01014622300863266, -0.0408673994243145, 0.016954703256487846, -0.09056374430656433, -0.03077513538300991, 0.03496457636356354, -0.02482164464890957, 0.03691611811518669, -0.04672284424304962, -0.07307673990726471, -0.0095...
0.019431
a special case in ``dateutil`` and should be constructed explicitly as an instance of ``dateutil.tz.tzutc``. You can also construct other time zones objects explicitly first. .. ipython:: python import pytz # pytz tz\_pytz = pytz.timezone("Europe/London") rng\_pytz = pd.date\_range("3/6/2012 00:00", periods=3, freq="D"...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.006333457306027412, -0.03431735932826996, 0.007066827267408371, 0.04424707964062691, -0.01981336437165737, -0.012507377192378044, -0.010043391957879066, 0.011799889616668224, -0.03314618766307831, -0.04747006669640541, -0.05720781534910202, -0.05205423757433891, -0.06879902631044388, 0....
-0.07762
will remove the time zone yielding the local time representation. ``tz\_convert(None)`` will remove the time zone after converting to UTC time. .. ipython:: python didx = pd.date\_range(start="2014-08-01 09:00", freq="h", periods=3, tz="US/Eastern") didx didx.tz\_localize(None) didx.tz\_convert(None) # tz\_convert(None...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.03983202204108238, 0.04420267790555954, 0.0006898084538988769, 0.03661345690488815, 0.09347102791070938, -0.09853405505418777, -0.03772486373782158, -0.0019905068911612034, 0.0012689756695181131, -0.03432691469788551, -0.02137397974729538, -0.025049693882465363, -0.10790245980024338, 0....
-0.053538
with a dtype of ``datetime64[ns, tz]`` where ``tz`` is the time zone .. ipython:: python s\_aware = pd.Series(pd.date\_range("20130101", periods=3, tz="US/Eastern")) s\_aware Both of these :class:`Series` time zone information can be manipulated via the ``.dt`` accessor, see :ref:`the dt accessor section `. For example...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/timeseries.rst
main
pandas
[ -0.003576466115191579, 0.020310619845986366, -0.06856885552406311, 0.00484642805531621, 0.02894161082804203, -0.08487612754106522, -0.04125156253576279, 0.00025694005307741463, -0.028860563412308693, -0.009264545515179634, -0.03628165274858475, -0.0597994327545166, -0.09145604074001312, -0...
0.007433
.. \_basics: {{ header }} ============================== Essential basic functionality ============================== Here we discuss a lot of the essential functionality common to the pandas data structures. To begin, let's create some example objects like we did in the :ref:`10 minutes to pandas <10min>` section: .. ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.02839665673673153, -0.007562311366200447, 0.07395020872354507, 0.0018466684268787503, 0.05663950368762016, -0.04734937101602554, -0.03649104759097099, -0.022814808413386345, 0.006188428495079279, 0.0017168006161227822, 0.00684167817234993, -0.01107074972242117, -0.08157812058925629, -0....
0.059175
the past, pandas recommended :attr:`Series.values` or :attr:`DataFrame.values` for extracting the data from a Series or DataFrame. You'll still find references to these in old code bases and online. Going forward, we recommend avoiding ``.values`` and using ``.array`` or ``.to\_numpy()``. ``.values`` has the following ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.04590850695967674, -0.04777420684695244, -0.060389406979084015, 0.030216356739401817, 0.08481280505657196, -0.06956770271062851, -0.0227397121489048, 0.0031967624090611935, 0.00835057720541954, -0.024401620030403137, 0.0010456269374117255, 0.02628893218934536, -0.11698700487613678, -0.0...
0.012725
at a location are missing. For example, when adding two DataFrame objects, you may wish to treat NaN as 0 unless both DataFrames are missing that value, in which case the result will be NaN (you can later replace NaN with some other value using ``fillna`` if you wish). .. ipython:: python df2 = df.copy() df2.loc["a", "...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.02860940434038639, -0.0704602301120758, -0.008939718827605247, -0.03171888738870621, 0.04282357543706894, -0.11218321323394775, -0.047653891146183014, -0.05179373174905777, 0.046453822404146194, 0.02527926303446293, 0.06318213045597076, -0.021397553384304047, -0.0404447540640831, -0.024...
-0.021393
where one is considered to be of "higher quality". However, the lower quality series might extend further back in history or have more complete data coverage. As such, we would like to combine two DataFrame objects where missing values in one DataFrame are conditionally filled with like-labeled values from the other Da...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.002973017515614629, -0.029677994549274445, 0.014166410081088543, -0.014835336245596409, 0.056821826845407486, -0.04307775944471359, 0.0004896504106000066, -0.03185165673494339, -0.043533578515052795, -0.02692435495555401, 0.06054697558283806, -0.0035350585822016, -0.012246617116034031, ...
-0.062004
a DataFrame (excluding NAs of course): .. ipython:: python series = pd.Series(np.random.randn(1000)) series[::2] = np.nan series.describe() frame = pd.DataFrame(np.random.randn(1000, 5), columns=["a", "b", "c", "d", "e"]) frame.iloc[::2] = np.nan frame.describe() You can select specific percentiles to include in the ou...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.0017267868388444185, -0.05165516585111618, -0.051689110696315765, -0.048239875584840775, 0.02955886349081993, -0.07857020944356918, 0.01765766739845276, 0.019131027162075043, 0.008992327377200127, 0.02991221845149994, 0.019145861268043518, -0.04831010103225708, -0.02308848686516285, -0....
-0.02043
``Series``, row- or column-wise, or elementwise. 1. `Tablewise Function Application`\_: :meth:`~DataFrame.pipe` 2. `Row or Column-wise Function Application`\_: :meth:`~DataFrame.apply` 3. `Aggregation API`\_: :meth:`~DataFrame.agg` and :meth:`~DataFrame.transform` 4. `Applying Elementwise Functions`\_: :meth:`~DataFram...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ 0.006065984256565571, -0.06071898713707924, -0.03596676141023636, -0.04532456770539284, -0.00007897131581557915, -0.1044919565320015, -0.022884327918291092, 0.033262744545936584, -0.026641106233000755, 0.023790506646037102, 0.013149881735444069, -0.021037084981799126, -0.05671213939785957, ...
-0.027559
- x.min()) df.apply(np.cumsum) df.apply(np.exp) The :meth:`~DataFrame.apply` method will also dispatch on a string method name. .. ipython:: python df.apply("mean") df.apply("mean", axis=1) The return type of the function passed to :meth:`~DataFrame.apply` affects the type of the final output from ``DataFrame.apply`` f...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.015481001697480679, -0.043447624891996384, -0.015738608315587044, -0.007604092825204134, 0.05722302570939064, -0.06584523618221283, -0.02519482932984829, 0.05338902398943901, 0.026566214859485626, 0.04424132779240608, 0.029307665303349495, 0.016048016026616096, -0.05928665027022362, -0....
0.022476
a scalar or a list of scalars, to ``DataFrame.agg`` allows you to customize which functions are applied to which columns. Note that the results are not in any particular order, you can use an ``OrderedDict`` instead to guarantee ordering. .. ipython:: python tsdf.agg({"A": "mean", "B": "sum"}) Passing a list-like will ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.0321526937186718, -0.043570853769779205, -0.024085301905870438, 0.02317875064909458, -0.03556045517325401, 0.02287275157868862, 0.02018592692911625, 0.02300289459526539, -0.001688192249275744, 0.034110795706510544, 0.028545886278152466, 0.0016977546038106084, -0.014562791213393211, -0.0...
0.019207
implement nearly all other features relying on label-alignment functionality. To \*reindex\* means to conform the data to match a given set of labels along a particular axis. This accomplishes several things: \* Reorders the existing data to match a new set of labels \* Inserts missing value (NA) markers in label locat...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.06903445720672607, -0.043259430676698685, -0.00119360804092139, -0.00783191341906786, 0.013481203466653824, 0.019672028720378876, 0.008453489281237125, -0.10015726089477539, 0.023045018315315247, 0.000632713723462075, 0.0921054407954216, 0.014953194186091423, -0.030076341703534126, -0.0...
0.033517
while reindexing ~~~~~~~~~~~~~~~~~~~~~~~~ :meth:`~Series.reindex` takes an optional parameter ``method`` which is a filling method chosen from the following table: .. csv-table:: :header: "Method", "Action" :widths: 30, 50 ffill, Fill values forward bfill, Fill values backward nearest, Fill from the nearest index value...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.09484215080738068, -0.02753567136824131, 0.005435486324131489, 0.03901071101427078, -0.06260816007852554, -0.057691603899002075, -0.03374861925840378, -0.03417746722698212, 0.010509388521313667, 0.03984786570072174, -0.019167698919773102, 0.03287437930703163, -0.049138352274894714, -0.0...
0.05084
a DataFrame gives you the column names: .. ipython:: python df = pd.DataFrame( {"col1": np.random.randn(3), "col2": np.random.randn(3)}, index=["a", "b", "c"] ) for col in df: print(col) pandas objects also have the dict-like :meth:`~DataFrame.items` method to iterate over the (key, value) pairs. To iterate over the ro...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.012529936619102955, -0.059029094874858856, -0.10833194851875305, -0.025505367666482925, 0.0634959414601326, -0.10020221769809723, -0.004001101944595575, -0.03645597770810127, -0.012215287424623966, 0.0019373453687876463, 0.001153816469013691, 0.06357531249523163, -0.065382219851017, -0....
-0.026071
first element of the tuple will be the row's corresponding index value, while the remaining values are the row values. For instance: .. ipython:: python for row in df.itertuples(): print(row) This method does not convert the row to a Series object; it merely returns the values inside a namedtuple. Therefore, :meth:`~Da...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.043674975633621216, -0.028999939560890198, -0.05036311596632004, -0.0023504849523305893, 0.03844283148646355, -0.08843719214200974, 0.0032999098766595125, -0.048632171005010605, -0.031318552792072296, 0.00797963235527277, 0.014063624665141106, 0.08829838037490845, -0.059945911169052124, ...
0.058842
s1 = pd.DataFrame({"a": ["B", "a", "C"], "b": [1, 2, 3], "c": [2, 3, 4]}).set\_index( list("ab") ) s1 .. ipython:: python s1.sort\_index(level="a") s1.sort\_index(level="a", key=lambda idx: idx.str.lower()) For information on key sorting by value, see :ref:`value sorting `. .. \_basics.sort\_values: By values ~~~~~~~~~...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ 0.03421627730131149, -0.005589949432760477, -0.045654721558094025, -0.04055134579539299, 0.01734893023967743, -0.004868585150688887, 0.026476386934518814, 0.028478365391492844, -0.005921502131968737, 0.04248031973838806, 0.025847595185041428, 0.1234542578458786, -0.017145588994026184, -0.0...
-0.039317
"two"), ("b", "three")] ) df1.sort\_values(by=("a", "two")) Copying ------- The :meth:`~DataFrame.copy` method on pandas objects copies the underlying data (though not the axis indexes, since they are immutable) and returns a new object. Note that \*\*it is seldom necessary to copy objects\*\*. For example, there are o...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.03938591852784157, -0.08136342465877533, 0.014718260616064072, -0.05541064217686653, 0.045322831720113754, -0.07727863639593124, 0.009834465570747852, -0.07424420863389969, -0.013334513641893864, 0.10433384776115417, 0.04163743555545807, 0.0909702256321907, -0.08126281201839447, -0.0204...
-0.01243
pd.Series([1] \* 3, dtype="int8"), } ) dft dft.dtypes On a ``Series`` object, use the :attr:`~Series.dtype` attribute. .. ipython:: python dft["A"].dtype If a pandas object contains data with multiple dtypes \*in a single column\*, the dtype of the column will be chosen to accommodate all of the data types (``object`` ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.01299006212502718, -0.09801024943590164, -0.012118217535316944, 0.011850712820887566, 0.017679905518889427, -0.04458026587963104, 0.04950372874736786, 0.031105272471904755, 0.016842620447278023, -0.035455089062452316, -0.07819496840238571, -0.0069221206940710545, -0.0868820771574974, 0....
0.048396
5, 6], "c": [7, 8, 9]}) dft.loc[:, ["a", "b"]].astype(np.uint8).dtypes dft.loc[:, ["a", "b"]] = dft.loc[:, ["a", "b"]].astype(np.uint8) dft.dtypes .. \_basics.object\_conversion: object conversion ~~~~~~~~~~~~~~~~~ pandas offers various functions to try to force conversion of types from the ``object`` dtype to other ty...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ -0.01876363903284073, -0.048013973981142044, 0.020194659009575844, 0.02747437171638012, 0.05189760401844978, -0.09845799207687378, 0.04734625294804573, 0.007911240682005882, -0.02911614440381527, -0.013523498550057411, -0.09016861021518707, -0.013370410539209843, -0.14839576184749603, 0.05...
0.031753
:class:`DataFrame` with a slew of different dtypes: .. ipython:: python df = pd.DataFrame( { "string": list("abc"), "int64": list(range(1, 4)), "uint8": np.arange(3, 6).astype("u1"), "float64": np.arange(4.0, 7.0), "bool1": [True, False, True], "bool2": [False, True, False], "dates": pd.date\_range("now", periods=3), "...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/basics.rst
main
pandas
[ 0.008394382894039154, -0.0024475688114762306, 0.07805199176073074, 0.04502205550670624, 0.02351626567542553, 0.02542959153652191, -0.021221302449703217, -0.06913922727108002, 0.006983546540141106, -0.04514511674642563, 0.03898226469755173, -0.05018974840641022, -0.10789310187101364, -0.010...
-0.052484
.. \_cookbook: {{ header }} \*\*\*\*\*\*\*\* Cookbook \*\*\*\*\*\*\*\* This is a repository for \*short and sweet\* examples and links for useful pandas recipes. We encourage users to add to this documentation. Adding interesting links and/or inline examples to this section is a great \*First Pull Request\*. Simplified...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ -0.09516572952270508, -0.01032527070492506, -0.05274812504649162, 0.03070397488772869, 0.12106896191835403, -0.04514110088348389, -0.048162154853343964, 0.004293129779398441, -0.03527965769171715, 0.0012955903075635433, 0.05238215997815132, 0.02825561724603176, -0.05869584530591965, -0.082...
0.124689
pd.DataFrame( {"AAA": [4, 5, 6, 7], "BBB": [10, 20, 30, 40], "CCC": [100, 50, -30, -50]} ) df df[(df.AAA <= 6) & (df.index.isin([0, 2, 4]))] Use loc for label-oriented slicing and iloc positional slicing :issue:`2904` .. ipython:: python df = pd.DataFrame( {"AAA": [4, 5, 6, 7], "BBB": [10, 20, 30, 40], "CCC": [100, 50,...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ 0.027231289073824883, 0.031311701983213425, -0.005133450962603092, -0.038203395903110504, 0.050649337470531464, 0.04618493467569351, 0.028376251459121704, -0.04714910686016083, 0.006032753270119429, -0.001260884222574532, 0.0298934169113636, -0.0039693331345915794, -0.0924360528588295, 0.0...
-0.018832
axis are optional, and default to zero df.xs("BB", level=0, axis=0) ...and now the 2nd level of the 1st axis. .. ipython:: python df.xs("six", level=1, axis=0) `Slicing a MultiIndex with xs, method #2 `\_\_ .. ipython:: python import itertools index = list(itertools.product(["Ada", "Quinn", "Violet"], ["Comp", "Math", ...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ 0.012660100124776363, -0.06935234367847443, -0.004596807062625885, -0.07910469174385071, 0.06680113077163696, -0.021029742434620857, 0.04654950276017189, -0.037976063787937164, -0.05477644130587578, 0.046061646193265915, 0.04996207728981972, 0.0003712824545800686, -0.036654651165008545, 0....
0.005354
{"line\_race": [10, 10, 8, 10, 10, 8], "beyer": [99, 102, 103, 103, 88, 100]}, index=[ "Last Gunfighter", "Last Gunfighter", "Last Gunfighter", "Paynter", "Paynter", "Paynter", ], ) df df["beyer\_shifted"] = df.groupby(level=0)["beyer"].shift(1) df `Select row with maximum value from each group `\_\_ .. ipython:: pytho...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ 0.015605955384671688, 0.015137355774641037, 0.04504340514540672, -0.037420179694890976, 0.03521241247653961, -0.01389634981751442, 0.07475617527961731, -0.09016302227973938, -0.03504716977477074, 0.00969809852540493, -0.017333464697003365, -0.01675102673470974, -0.017102723941206932, -0.02...
-0.060823
i in range(len(df) - 50) } ) s `Rolling apply with a DataFrame returning a Scalar `\_\_ Rolling Apply to multiple columns where function returns a Scalar (Volume Weighted Average Price) .. ipython:: python rng = pd.date\_range(start="2014-01-01", periods=100) df = pd.DataFrame( { "Open": np.random.randn(len(rng)), "Clo...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ -0.011081557720899582, -0.031126849353313446, 0.0013695138040930033, -0.027749793604016304, -0.006378610152751207, -0.04442327469587326, 0.008141908794641495, -0.04044992849230766, 0.021279403939843178, -0.009227953851222992, -0.006845158990472555, -0.03078625351190567, -0.07599066942930222,...
-0.022162
lines of a frame `\_\_ Reading a file that is compressed but not by ``gzip/bz2`` (the native compressed formats which ``read\_csv`` understands). This example shows a ``WinZipped`` file, but is a general application of opening the file within a context manager and using that handle to read. `See here `\_\_ `Inferring d...
https://github.com/pandas-dev/pandas/blob/main//doc/source/user_guide/cookbook.rst
main
pandas
[ -0.07089059799909592, -0.02563495561480522, -0.08916334807872772, 0.036246538162231445, 0.04353823512792587, -0.0631083995103836, 0.02824699506163597, 0.0028061375487595797, -0.014031222090125084, 0.030569452792406082, -0.01607772894203663, 0.029633013531565666, -0.0010637817904353142, 0.0...
-0.00523