0

I am working with a dataframe, that unfortunately imports the column "ID" in the following format: 7.350943+e

I thought I fixed the issue with this code:

pd.set_option('display.float_format', lambda x: '%3.f' % x) 

However, this only fixes the display, in the back-end it remains in this scientific format.

When I try to create a new column based on column ID and column source, I get the following:

df['Primary_key']=df['ID'].apply(str)+'_'+df['Source'] Name ID Source Primary_key John 782857635 email 782857635.0_email 

What format do I need to change the datatype to in order to get rid of the .0?

df['ID'].values array([782929635.0, 783063368.0, 782960457.0, ..., 783257941.0, 783535550.0, nan], dtype=object) 

I tried replacing it, in the Primary key, but it didn't work (there was no change to the dataframe)

df['Primary_key']= df['Primary_key'].str.strip().replace(".0_","_") 

2 Answers 2

1

I think you should try something like:

df['ID'] = df['ID'].apply(str).strip().replace(".0","") 
Sign up to request clarification or add additional context in comments.

Comments

1

int() is what you seem to be looking for.

[int(i) for i in whateverList] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.