I have two Pandas dataframes called newframe, and portfoliotickerlookup. newframe…
- User
I have two Pandas dataframes called new_frame, and portfolio_ticker_lookup.
new_frame exchange ticker portfolio_id is_primary 0 NYSE Arca DFAU 2 True 1 NYSE Arca DFAI 3 True 2 NYSE Arca DFAE 4 True 3 NYSE Arca DFAT 5 True 4 NYSE Arca DFAS 6 True 5 NYSE Arca DFUS 7 True 6 NYSE Arca DFAC 8 True
new_frame has the following dtypes: exchange object ticker object portfolio_id int64 is_primary bool dtype: object
portfolio_ticker_lookup portfolio_id ticker
DFAU 2 DFAI 3 DFAE 4 DFAT 5 DFAS 6 DFUS 7 DFAC 8portfolio_ticker_lookup has the following dtypes: portfolio_id int64 dtype: object
What steps do I need to take before I can the following line without any error? new_frame.join(portfolio_ticker_lookup, on="portfolio_id", how="inner")
- Assistant
Before you can run the above line without any error, you need to make sure that the "portfolio_id" column in both dataframes is of the same dtype. From the provided information, it seems like the "portfolio_id" column in the "new_frame" dataframe is of type int64, while the "portfolio_id" column in the "portfolio_ticker_lookup" dataframe is also of type int64.
If both columns are of the same dtype, you can directly use the join operation as follows:
new_frame.join(portfolio_ticker_lookup, on="portfolio_id", how="inner")
However, if the dtype of the "portfolio_id" column in either dataframe is different, you need to ensure that both columns have the same dtype before performing the join operation. Here are the steps you can take to convert the dtype if necessary:
- Check the dtype of the "portfolio_id" column in both dataframes using the dtypes attribute:
new_frame["portfolio_id"].dtype portfolio_ticker_lookup["portfolio_id"].dtype