Code Me, dsewnr

Pandas NaN to None

October 22, 2019

上次處理資料找了一次答案,今天處理資料又用到,記錄一下。

Python Pandas 讀取 csv 檔把 NaN 轉成 None

import pandas as pd
import numpy as np

df = pd.read_csv("xxx.csv", encoding='utf8', header=None, low_memory=False)
df = df.replace({pd.np.nan: None})

dsewnr

Written by dsewnr who lives and works in Taiwan has interest in new things. Please feel free to contact me: EmailGitHubLinkedInTwitter. You can also subscribe by email.

Partners: Liyang's Blog