Financial Data Preprocessing: Techniques and Applications
1. Filtering DataFrames
When dealing with data analysis, filtering a DataFrame to focus on specific observations is a common task. For instance, if you want to view the top 12 observations of monthly data from the year 2010 onward in a DataFrame named df_cpi_2 , you can use the following code:
df_cpi_2.query("period_type == 'monthly' and year >= 2010") \
.loc[:, ["date", "value"]] \
.set_index("date") \
.head(12)
This code first uses the query method to filter the DataFrame based on the conditions period_type == 'monthly' and year >= 2010 . Then, it selects
超级会员免费看
订阅专栏 解锁全文
2089

被折叠的 条评论
为什么被折叠?



