0

I checked the answer here but this doesn't work for me.

How to get the integer portion of a float column in pandas

As I need to write further conditional statements which will perform operations on the exact values in the columns and the corresponding values in other columns.

So basically I am hoping that for my two dataframes df1 and df2 I will form a concatenated dataframe using

dfn_c = pd.concat([dfn_1, dfn_2], axis=1)

then write something like

dfn_cn = dfn_c.loc[df1.X1.isin(df2['X2'])]

where X1 and X2 are the said columns respectively. The above line of course makes an exact comparison whereas I want to compare only the integer portion and then form the new dataframe.

  • 1
    Please include a small subset of your data as a __copyable__ piece of code that can be used for testing as well as your expected output. See [MRE - Minimal, Reproducible, Example](https://stackoverflow.com/help/minimal-reproducible-example), and [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker May 16 '21 at 15:49

1 Answers1

0

IIUC, try casting to int then compare.

dfn_cn = dfn_c.loc[df1['X1'].astype(int).isin(df2['X2'].astype(int))]
sushanth
  • 8,275
  • 3
  • 17
  • 28