0

I have this Pandas DataFrame and I have to convert some of the items into coordinates, (meaning they have to be floats) and it includes the indexes while trying to convert them into floats. So I tried to set the indexes to the first thing in the DataFrame but it doesn't work. I wonder if it has anything to do with the fact that it is a part of the whole DataFrame, only the section that is "Latitude" and "Longitude".

df = df_volc.iloc(axis = 0)[0:, 3:5]

df.set_index("hello", inplace = True, drop = True) df

and I get the a really long error, but this is the last part of it: KeyError: '34.50'

if I don't do the set_index part I get:

Latitude Longitude 0 34.50 131.60 1 -23.30 -67.62 2 14.50 -90.88

I just wanna know if its possible to get rid of the indexes or set them.

2
  • .set_index Set the DataFrame index (row labels) using one or more existing columns Commented Aug 28, 2018 at 0:20
  • The "hello" is supposed to be "34.50" Commented Aug 28, 2018 at 20:21

1 Answer 1

1

The parameter you need to pass to set_index() function is keys : column label or list of column labels / arrays. In your scenario, it seems like "hello" is not a column name.

I just wanna know if its possible to get rid of the indexes or set them.

It is possible to replace the 0, 1, 2 index with something else, though it doesn't sound like it's necessary for your end goal:

to convert some of the items into [...] floats

To achieve this, you could overwrite the existing values by using astype():
df['Latitude'] = df['Latitude'].astype('float')

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.