資料框由具有一些隱藏字符的“值”列組成。
當我將資料框寫入 PostgreSQL 時,出現以下錯誤
ValueError: A string literal cannot contain NUL (0x00) characters.我有些如何找到錯誤的原因。參考下表(缺少列值
| | datetime | mc | tagname | value | quality |
|-------|--------------------------|----|---------|------------|---------|
| 19229 | 16-12-2021 02:31:29.083 | L | VIN | | 192 |
| 19230 | 16-12-2021 02:35:28.257 | L | VIN | C4A 173026 | 192 |
- 檢查字串的長度 - 它與下面的行一樣有 10 個字符

df.value.str.len()

要求:
我想用文本“miss”替換那個空白區域,我在熊貓中嘗試了不同的方法。我做不到。
df['value'] = df['value'].str.replace(r"[\"\',]", '')<br />
df.replace('\'','', regex=True, inplace=True)
| | datetime | mc | tagname | value | quality |
|-------|--------------------------|----|---------|------------|---------|
| 19229 | 16-12-2021 02:31:29.083 | L | VIN | miss | 192 |
| 19230 | 16-12-2021 02:35:28.257 | L | VIN | C4A 173026 | 192 |
uj5u.com熱心網友回復:
試試這個:
df['value'] = df['value'].str.replace(r'[\x00-\x19]', '').replace('', 'miss')
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385351.html
標籤:Python 熊猫 PostgreSQL的
