I have a CSV file which has stock market data by date and symbol. It has various columns like date, Max price, Min price and so on. I must resample these data with 10 days frequency from last four months of 2019 until the first three months of 2020, and then filter the Min.mean()
above than 20000 and Max.mean()
less than 35000. i wrote this code:
import numpy as np
import pandas as pd
from datetime import datetime
stock_df = pd.read_csv('stock_data.csv')
stock_df.drop(columns = ['Unnamed: 0'],inplace=True)
column_names = {
"تاریخ":"str_date",
"اولین قیمت":"Open",
"نماد":"Symbol",
"نام":"Name",
"قیمت پایانی":"Close",
"قیمت آخرین معامله":"Last Trade",
"تعداد معاملات":"Quantity",
"حجم":"Volume",
"ارزش":"Value",
"کمترین قیمت":"Min",
"بیشترین قیمت":"Max",
"قیمت دیروز":"Yesterday Price",
"تغییر":"Change"}
stock_df.rename(columns=column_names,inplace=True)
stock_df["date"] = pd.to_datetime(stock_df["str_date"])
The original attempt was like this:
stock_df.set_index('date',inplace=True)
result = stock_df.loc["2019-09":"2020-03"].resample('10D').Max.mean()<=35000 & stock_df.loc["2019-09":"2020-03"].resample('10D').Min.mean()>=20000
stock_df
is the DataFrame that holds CSV file data. The final answer must put in the dataframe result
. but this code gets this error:
TypeError: Cannot perform 'rand_' with a dtyped [float64] array and scalar of type [bool]