替换pandas Dataframe列中的Unicode字符

时间:2018-03-24 14:28:34

标签: python pandas replace

我有一个pandas Dataframe的问题,其中包括公寓中的房间数量(类型字符串)。

此数据包含一个unicode字符 u" \ u00BD" https://www.fileformat.info/info/unicode/char/00bd/index.htm)。

如何有效地用十进制值替换此字符,以便数据读取scramble :: ∀ eff. String -> Eff (random :: RANDOM | eff) String scramble s = foldM insertRnd (take 1 s) (toCharArray $ drop 1 s) insertRnd :: ∀ eff. String -> Char -> Eff (random :: RANDOM | eff) String insertRnd st ch = do n <- randomInt 0 $ length st pure $ insertAt n ch st 而不是unicode字符。

目前看起来像这样: /node_modules/webpack/lib/Compiler.js:96 apply: util.deprecate((...args) => { ^^^ SyntaxError: Unexpected token ... at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Module._extensions..js (module.js:422:10) at Object.require.extensions.(anonymous function) [as .js] (/home/zaba/code/CurrencyCalc/node_modules/babel-register/lib/node.js:152:7) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/zaba/code/CurrencyCalc/node_modules/webpack/lib/webpack.js:7:18) at Module._compile (module.js:413:34) npm ERR! Linux 4.13.0-37-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start" npm ERR! node v5.12.0 npm ERR! npm v3.8.6 npm ERR! code ELIFECYCLE npm ERR! currencycalc@1.0.0 start: `babel-node buildScripts/server.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the currencycalc@1.0.0 start script 'babel-node buildScripts/server.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the currencycalc package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! babel-node buildScripts/server.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs currencycalc npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls currencycalc npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /home/zaba/code/CurrencyCalc/npm-debug.log 我希望列中的值为2.5, 3.5, 4.5 etc (Still String format)

1 个答案:

答案 0 :(得分:1)

您可以使用以下方法修复列:

df['rooms'] = df['rooms'].str.replace("½", ".5")

使其成为浮动:

df['rooms'] = df['rooms'].str.replace("½", ".5").apply(float)