Issue
I have a data frame which has information on 1000 stocks (open, close, high , low, volume, company name, ticker symbol etc.) and I have another dataframe which just has one column of ticker symbols and this second dataframe has fewer rows than 1000 rows in the first dataframe. Now, I want only those rows in the first dataframe for which the ticker symbol is available in the second dataframe. How can this be done using pandas ? In my case, I have small dataframes. But I would also like to know how this operation can be scaled up. So, please suggest efficient way as well.
Thanks
Solution
You can use .isin() to filter to the list of tickers available in df2.
df1_filtered = df1[df1['ticker'].isin(df2['ticker'].tolist())]
Answered By - Shubham Periwal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.