在熊猫数据框中找到非NAN元素的总数

我知道df.count()和df.groupby.count(),但是我只是想要数据帧中特定列(例如称为“汽车”)的非NAN元素的数量。

我知道df.size [0],但是此命令不尊重非NAN元素的数量在不同列中可能不同的事实。

geaixin520 回答:在熊猫数据框中找到非NAN元素的总数

还有# download input images to disk input_images = @user.photos.first(25) .map { |photo| photo.image[:thumb] } .map(&:download) # create temporary file for output image processed_image = Tempfile.new ["montage",".jpg"],binmode: true MiniMagick::Tool::Montage.new do |montage| montage.merge! input_images.map(&:path) montage.tile "5x5" montage << processed_image.path end attachments.inline['images.jpg'] = File.binread(processed_image.path) # close and delete temporary files [*input_images,processed_image].each(&:close!) 系列。它还忽略count。来自文档

NaN

因此,对于列s = pd.Series([0.0,1.0,np.nan]) s.count() Out[307]: 2

cars

将返回列df['cars'].count() 的Non-NaN值的数量

,

我们还可以使用Series.notna + Series.sum

df.cars.notna().sum()
本文链接:https://www.f2er.com/3163208.html

大家都在问