#π anyone help me convert this columns to certains types
25 messages Β· Page 1 of 1 (latest)
@candid wolf
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
how were you trying?
And what happens?
didn't work
That's not very descriptive. Do you get an error?
here is my code ```py
for i in ['peak', 'online', 'follows']:
df1[i] = df1[i].str.replace(',', '').str.replace('β', '')
df1[i] = df1[i].astype(int)
the column 'peak' converted to int successfuly
but the other failed
i guess because of the empty raws
The error actually sounds like one of these columns is already numeric, rather. What does df1.info() say?
peak is int but other are all object
Well, because peak already got converted to int, you can't use this piece of code again because it'll fail on trying to do df1["peak"].str.
As for the empty rows, to represent them you could replace them with pd.NA and then do .astype("Int64") - that's a pandas dtype that allows NA values.
alr will try that
what am i doing wrong here?
it remains as an object type
.astype isn't an inplace operation. You need to assign the new column back to df1 or you're just discarding it.
thanks man it worked
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.