1

I have a dataframe called df['code'] which looks like this.

0          1
1          2
2          3
3          6
4          9
5         12
6         15

in which the first column are indexes and the second one is the column I wanted to convert to integers.

What I tried to do is:
for i in range(len(df['code'])): df['code'][i] = int(df['code'][i])

which did not work. Any ideas? Thanks

1
  • 1
    df['columns'].astype(int) Commented May 16, 2019 at 1:37

1 Answer 1

1

I think one way to do this would be:

for i in range(len(df['code'])):
    df['code'].iloc[i] = int(df['code'].iloc[i] )

Instead of using the index itself, it uses the index position.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.