我有一些我需要用NaT取代的NaN系列。我怎么能这样做?
以下是我迄今为止尝试过的一个简单示例:
>>> s = pd.Series([np.NaN, np.NaN])
>>> s.fillna(pd.NaT)
0 NaN
1 NaN
dtype: float64
>>> s.replace(np.NaN, pd.NaT)
0 NaN
1 NaN
dtype: float64
>>> s.where(pd.notnull(s), pd.NaT)
0 NaN
1 NaN
dtype: object
pandas版本:0.16.2
numpy版本:1.9.2
python版本:2.7.10
答案 0 :(得分:8)
dtype
首先将NaT
转换为dtype
,float
最初是dtype
In [90]:
s.astype(np.datetime64).fillna(pd.NaT)
Out[90]:
0 NaT
1 NaT
dtype: datetime64[ns]
时无意义:
NaN
如果系列中有非to_datetime
值,请使用In [97]:
s = pd.Series([np.NaN, np.NaN, 1.0])
pd.to_datetime(s)
Out[97]:
0 NaT
1 NaT
2 1970-01-01 00:00:00.000000001
dtype: datetime64[ns]
:
let str = "Working at Parse is great!"
let data = str.dataUsingEncoding(NSUTF8StringEncoding)
let file = PFFile(name:"resume.txt", data:data)
file.saveInBackgroundWithBlock({
(succeeded: Bool, error: NSError?) -> Void in
// Handle success or failure here ...
}, progressBlock: {(percentDone: Int32) -> Void in
// Update your progress spinner here. percentDone will be between 0 and 100.
})