Warning: preg_grep(): Compilation failed: quantifier does not follow a repeatable item at offset 142 in /var/www/tg-me/post.php on line 75
Библиотека собеса по Data Science | вопросы с собеседований | Telegram Webview: ds_interview_lib/247 -
Telegram Group & Telegram Channel
🐼 Задача на знание Pandas

Условие: У вас есть датафрейм df, содержащий два столбца: A и B. Столбец A содержит даты, а столбец B — числовые значения. Как бы вы рассчитали скользящее среднее по столбцу B с окном в 3 дня, предполагая, что значения в столбце A идут подряд и без пропусков?

Решение:
import pandas as pd

data = {
'A': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05',
'2023-01-06', '2023-01-07', '2023-01-08', '2023-01-09'],
'B': [18, 71, 13, 57, 7, 8, 69, 83, 27]
}

df = pd.DataFrame(data)

# Убедимся, что столбец A распознан как дата
df['A'] = pd.to_datetime(df['A'])

# Установим столбец дат как индекс датафрейма
df = df.set_index('A')

# Рассчитаем скользящее среднее по столбцу B с окном в 3 дня
df['Moving_Average'] = df['B'].rolling(window=3).mean()

print(df)


#python
#pandas
#программирование
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/ds_interview_lib/247
Create:
Last Update:

🐼 Задача на знание Pandas

Условие: У вас есть датафрейм df, содержащий два столбца: A и B. Столбец A содержит даты, а столбец B — числовые значения. Как бы вы рассчитали скользящее среднее по столбцу B с окном в 3 дня, предполагая, что значения в столбце A идут подряд и без пропусков?

Решение:

import pandas as pd

data = {
'A': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05',
'2023-01-06', '2023-01-07', '2023-01-08', '2023-01-09'],
'B': [18, 71, 13, 57, 7, 8, 69, 83, 27]
}

df = pd.DataFrame(data)

# Убедимся, что столбец A распознан как дата
df['A'] = pd.to_datetime(df['A'])

# Установим столбец дат как индекс датафрейма
df = df.set_index('A')

# Рассчитаем скользящее среднее по столбцу B с окном в 3 дня
df['Moving_Average'] = df['B'].rolling(window=3).mean()

print(df)


#python
#pandas
#программирование

BY Библиотека собеса по Data Science | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/ds_interview_lib/247

View MORE
Open in Telegram


Библиотека собеса по Data Science | вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

Библиотека собеса по Data Science | вопросы с собеседований from us


Telegram Библиотека собеса по Data Science | вопросы с собеседований
FROM USA