MCPcopy
hub / github.com/pandas-dev/pandas / ohlc

Method ohlc

pandas/core/groupby/groupby.py:3543–3654  ·  view source on GitHub ↗

Compute open, high, low and close values of a group, excluding missing values. For multiple groupings, the result index will be a MultiIndex Returns ------- DataFrame Open, high, low and close values within each group. See Also

(self)

Source from the content-addressed store, hash-verified

3541
3542 @final
3543 def ohlc(self) -> DataFrame:
3544 """
3545 Compute open, high, low and close values of a group, excluding missing values.
3546
3547 For multiple groupings, the result index will be a MultiIndex
3548
3549 Returns
3550 -------
3551 DataFrame
3552 Open, high, low and close values within each group.
3553
3554 See Also
3555 --------
3556 DataFrame.agg : Aggregate using one or more operations over the specified axis.
3557 DataFrame.resample : Resample time-series data.
3558 DataFrame.groupby : Group DataFrame using a mapper or by a Series of columns.
3559
3560 Examples
3561 --------
3562
3563 For SeriesGroupBy:
3564
3565 >>> lst = [
3566 ... "SPX",
3567 ... "CAC",
3568 ... "SPX",
3569 ... "CAC",
3570 ... "SPX",
3571 ... "CAC",
3572 ... "SPX",
3573 ... "CAC",
3574 ... ]
3575 >>> ser = pd.Series([3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 0.1, 0.5], index=lst)
3576 >>> ser
3577 SPX 3.4
3578 CAC 9.0
3579 SPX 7.2
3580 CAC 5.2
3581 SPX 8.8
3582 CAC 9.4
3583 SPX 0.1
3584 CAC 0.5
3585 dtype: float64
3586 >>> ser.groupby(level=0).ohlc()
3587 open high low close
3588 CAC 9.0 9.4 0.5 0.5
3589 SPX 3.4 8.8 0.1 0.1
3590
3591 For DataFrameGroupBy:
3592
3593 >>> data = {
3594 ... 2022: [1.2, 2.3, 8.9, 4.5, 4.4, 3, 2, 1],
3595 ... 2023: [3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 8.2, 1.0],
3596 ... }
3597 >>> df = pd.DataFrame(
3598 ... data, index=["SPX", "CAC", "SPX", "CAC", "SPX", "CAC", "SPX", "CAC"]
3599 ... )
3600 >>> df

Callers

nothing calls this directly

Calls 5

is_numeric_dtypeFunction · 0.90
DataErrorClass · 0.90
_cython_operationMethod · 0.80

Tested by

no test coverage detected