I'm trying to round float series pulled from yfinance to two decimal places. Despite using round(2)
and astype('float32')
, the dataframe refuses to keep the round and shows multiple decimal places for each series. What am I doing wrong?
def clean_df(df):
return (df
.stack(level=0)
.swaplevel(0,1,axis=0)
.sort_index(axis=0, level=None, ascending=True)
.reset_index(level=[0,1])
.rename(columns={"level_0": "Symbol"})
.round({'Open': 2, 'High': 2,'Low': 2,'Close': 2,'Volume': 0})
.astype({'Symbol':'string','Close':'float32','Open':'float32','High':'float32','Low':'float32','Volume':'int32'})
)