Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Since pandas uses numpy for these computations under the hood, I would have suggested to use df.mean(keepdims=True), but apparently this has been explicitly disabled by pandas. However, after look...
Answer
#4: Post edited
- Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently this has been explicitly disabled by `pandas`.
However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), I noticed you should be able to get the desired result as follows:- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
- Note that this will introduce a row (with index) for each function.
- Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently this has been explicitly disabled by `pandas`.
- However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), I noticed you should be able to get the desired result as follows (note the `[]`):
- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
- Note that this will introduce a row (with index) for each function.
#3: Post edited
Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently that has also been blocked by `pandas`.- However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), I noticed you should be able to get the desired result as follows:
- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
Note that this will introduce an index for each function.
- Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently this has been explicitly disabled by `pandas`.
- However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), I noticed you should be able to get the desired result as follows:
- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
- Note that this will introduce a row (with index) for each function.
#2: Post edited
- Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently that has also been blocked by `pandas`.
However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), you should be able to get the desired goal as follows:- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
- Note that this will introduce an index for each function.
- Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently that has also been blocked by `pandas`.
- However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), I noticed you should be able to get the desired result as follows:
- ```python
- >>> df.agg(["mean"])
- A B
- mean 2.5 6.5
- ```
- The list can also contain functions and/or more operations.
- Note that this will introduce an index for each function.
#1: Initial revision
Since `pandas` uses `numpy` for these computations under the hood, I would have suggested to use `df.mean(keepdims=True)`, but apparently that has also been blocked by `pandas`. However, after looking into the [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.aggregate.html#pandas.DataFrame.aggregate), you should be able to get the desired goal as follows: ```python >>> df.agg(["mean"]) A B mean 2.5 6.5 ``` The list can also contain functions and/or more operations. Note that this will introduce an index for each function.