简体   繁体   中英

Divide two columns in a dataframe

I would like to divide the values of two columns in a df in python.

So far I have

df3['Result'] = df3[1_x]/df3[1_y]

The columns formed after an inner merge. I keep on getting the error SyntaxError: invalid decimal literal

Does anyone know how to fix this?

Missing single quotes for column names 1_x and 1_y :

df3['Result'] = df3['1_x'] / df3['1_y']
#                   ^   ^        ^   ^

Reproducible error:

>>> 1_x
  File "<ipython-input-4828-dea8fc3e99c1>", line 1
    1_x
     ^
SyntaxError: invalid decimal literal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM