2

I encountered a Problem after importing JSON-Data. Usually _to_numeric_ is working fine, but not in this Case. I have a column of strings Looking like this: 10.2100 10.2400 ...

I am using Jupyter Notebook. I have tried astype(), _infer_objects(), but still the data keeps behaving like string. I checked this by multiplying the column with 2 and get: 10.210010.2100 10.240010.2400 ...

This is the Code:

df = pd.DataFrame()
temp = pd.DataFrame()
for file in filelist:
    with open(path+file, "r", encoding="windows-1252") as f:
        xml_string = f.read()
        if xml_string.find("<") >= 0:
            json_string = convert_to_json(xml_string)
            flat = flatten_json.flatten(json.loads(json_string))
            temp = pd.DataFrame.from_dict(flat, orient='index').transpose()
            df = df.append(temp, sort=False)

df = df.reset_index()
pd.to_numeric(df.['Telegram_PRC_VALS_STP_2_VAL_0_NUM'])
df['Telegram_PRC_VALS_STP_2_VAL_0_NUM'] = df['Telegram_PRC_VALS_STP_2_VAL_0_NUM']*2
´´´

Any ideas? As this is my first Question in here I hope I am meeting your expectations on decently asking Questions.

1 Answer 1

2

You have to reassign output of to_numeric back, because it is not inplace method:

df['Telegram_PRC_VALS_STP_2_VAL_0_NUM']=pd.to_numeric(df['Telegram_PRC_VALS_STP_2_VAL_0_NUM'])
Sign up to request clarification or add additional context in comments.

1 Comment

thank you! I must have missed that combination. I tried df = df.infer_objects() thinking that should work, but that column remained an object.

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.