I
I
Ivan Smirnov2020-08-02 22:11:55
Python
Ivan Smirnov, 2020-08-02 22:11:55

How to solve a Python problem?

The Yandex Practicum simulator does not miss the seemingly correct solution Tasks:

Group the data by the 'month' column and find the average position in the output by month (level). Display the result of the grouping.

Decision:

import pandas as pd
position = pd.read_csv('/datasets/position.csv')
position['timestamp'] = pd.to_datetime(position['timestamp'], format='%Y-%m-%dT%H:%M:%S')
position['month'] = pd.DatetimeIndex(position['timestamp']).month
print(position.groupby('month')['level'].mean())


The simulator swears:
5f271019dff42050954103.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Skotchevich, 2020-08-03
@Skotchevich

groupby can group by more than just one column.
Here is an example of a correct function call: df.groupby(['A', 'B']).
Look closely at the difference in the function argument.

M
MechanicZelenyy, 2020-08-03
@MechanicZelenyy

Check the pandas version for you and for yandex, they may differ. If everything works locally for you, then they have a bug.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question