tom
tom

Reputation: 307

How to removing trailing .0 from a series column

I am trying to remove the trailing .0 from the rows of CAS/ID NO column using this code:

import requests
import pandas as pd

url = ' https://www.accessdata.fda.gov/scripts/sda/sdNavigation.cfm?sd=edisrev&displayAll=true'
html = requests.get(url).content
df_list2 = pd.read_html(html)
df2 = df_list2[0]
df3=df2.dropna(subset = ['CAS/ID NO'])
df3['CAS'] = df3['CAS/ID NO'].to_string()
df3['CAS'] = df3['CAS/ID NO'].astype(str).replace('\.0', '', regex=False)
df3

It is steadfastly resisting all of my efforts.

Upvotes: 0

Views: 53

Answers (1)

HedgeHog
HedgeHog

Reputation: 25196

You could try to convert in to type .astype('int64'):

df2['CAS'] = df2['CAS/ID NO'].astype('int64')

Example

import requests
import pandas as pd

url = ' https://www.accessdata.fda.gov/scripts/sda/sdNavigation.cfm?sd=edisrev&displayAll=true'
html = requests.get(url).content
df_list2 = pd.read_html(html)
df2 = df_list2[0]
df2 = df2.dropna(subset = ['CAS/ID NO']).copy()
df2['CAS'] = df2['CAS/ID NO'].astype('int64')

df2

Upvotes: 1

Related Questions