![](/img/trans.png)
[英]Sending Pandas Dataframe with Int64 type to GCP Spanner INT64 column
[英]Replace int64 value with “None” based on condition of another column in pandas dataframe
您可以替換單個列並更改其類型:
df['foo'] = df['foo'].astype(np.object)
然后:
df['foo'][0] = None
請注意,這將使列上的任何處理變慢,因為類型現在是Python對象,而不是數組中的整數。
嘗試這個
數據
id kpoints Rpoints Wpoints
0 1 1241 -1 1466
1 2 0 1475 0
2 3 0 1586 0
3 4 0 -1 0
采用
data.loc[(data['Rpoints'] != -1) & (data['kpoints'] == 0), 'kpoints'] = None
data.loc[(data['Rpoints'] != -1) & (data['Wpoints'] == 0), 'Wpoints'] = None
產量
id kpoints Rpoints Wpoints
0 1 1241.0 -1 1466.0
1 2 NaN 1475 NaN
2 3 NaN 1586 NaN
3 4 0.0 -1 0.0
簡單的data.dropna()
將刪除所有na行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.