问题描述
我的数据框具有nan。但是我试图找到明智的最小和最大。我怎么找到它。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == messageCollectionView {
let contentInset = scrollView.adjustedContentInset
if scrollView.contentOffset.y <= -contentInset.top && !isLoading {
self.loadMoreData(state: "Loading PrevIoUs")
} else if (scrollView.contentSize.height - scrollView.frame.height <= scrollView.contentOffset.y) && !isLoading {
self.loadMoreData(state: "Loading Next")
}
}
}
func loadMoreData( state : String ) {
if !self.isLoading {
self.isLoading = true
dispatchQueue.global().async {
// Fake background loading task for 2 seconds
sleep(2)
// Download more data here
dispatchQueue.main.async {
self.showToast(message: state)
self.isLoading = false
}
}
}
}
我正试图在每一行中找到最小值和最大值,并在列df = pd.DataFrame({"A":[12,NaN,13],"B":[45,12,65],"C":[63,78,NaN]})
df=
A B C
0 12 45 63
1 NaN 12 78
2 13 65 NaN
A
和B
中找到它们之间的差异。
我的代码:
C
当前输出:
poacols = ['A','B','C']
df['dif'] = np.nanmax(df[poacols])-np.nanmin(df[poacols])
预期输出:
df['dif'] =
0 66
1 66
2 66
解决方法
我们应该添加轴= 1,检查每行的最小和最大
np.nanmax(df[poacols],1)-np.nanmin(df[poacols],1)
Out[81]: array([51.,66.,52.])