根据 join in python with panda 的结果将 float 转换为 integer
Converting float to integer based on the result of join in python with panda
我正在进行左右联接以获取我的数据。现在我想将固定文本“Hello/ProductID=”与我的连接结果连接起来,该结果必须是整数。我不知道为什么我得到的结果是浮点数?
因为这是我的 URL 我需要将其转换为整数:
df = df.join(df.set_index(['ID','Type'])['ProductID'].rename('PID'), on=['ID','UniqueCode'])
df["URL"]= "Hello/ProductID=" + df['PID'].apply(str)
真实结果如下:
Hello/ProductID=1221.0
我的预期结果应该如下:
Hello/ProductID=1221
我尝试复制条件,因为 PID
是 float
类型。您可能必须将其转换为 integar
类型才能获得所需的结果。
我使用替换方法删除了 .0:
df['URL'] = df['URL'].str.replace('\.0$', ' ')
我正在进行左右联接以获取我的数据。现在我想将固定文本“Hello/ProductID=”与我的连接结果连接起来,该结果必须是整数。我不知道为什么我得到的结果是浮点数? 因为这是我的 URL 我需要将其转换为整数:
df = df.join(df.set_index(['ID','Type'])['ProductID'].rename('PID'), on=['ID','UniqueCode'])
df["URL"]= "Hello/ProductID=" + df['PID'].apply(str)
真实结果如下:
Hello/ProductID=1221.0
我的预期结果应该如下:
Hello/ProductID=1221
我尝试复制条件,因为 PID
是 float
类型。您可能必须将其转换为 integar
类型才能获得所需的结果。
我使用替换方法删除了 .0:
df['URL'] = df['URL'].str.replace('\.0$', ' ')