简体   繁体   English

将0值添加到Excel中的缺失数据

[英]Adding 0 values to absent data in Excel

Over the past 20 years a bunch of wildlife counts have been conducted in a whole bunch of places across a country. 在过去的20年中,整个国家/地区的许多地方都对野生生物进行了计数。 When a species is detected, the amount of individuals is written down along with the location, year etc. If a species is not detected, it is not included in the count (not even as 0 of this species detected). 当检测到一个物种时,会记录其个体数量以及位置,年份等。如果未检测到物种,则不包括在计数中(甚至不会检测到该物种的0)。

I have two datasheets. 我有两个数据表。 One with all the count data (ie how many of each species were seen at which location each year) and a sheet with where and when each count was conducted. 一个包含所有计数数据(即,每年在哪个位置看到多少个物种)和一张记录每个计数的时间和地点的表。 I think to run any meaningful stats on this dataset I would need to add a 0 count to every year and location when a species wasn't detected when it had been detected at this location in different years. 我认为要在此数据集上运行任何有意义的统计信息,当在不同年份在此位置检测到某个物种时,如果未检测到物种,则需要在每年和每个位置添加一个0计数。

For example if I had a dataset that ran from 2003-2008 and Species A was detected at Location B in 2004, 2005, 2006, and 2008, I would like to add a count of 0 for species A at Location B in 2003 and 2007. 例如,如果我有一个2003-2008年的数据集,并且在2004、2005、2006和2008年在位置B处检测到物种A,那么我想在2003和2007年在位置B处将物种A的计数加0 。

Is there an automatic way to do this? 有自动的方法吗? My data set is about 34000 rows so doing this manually would probably take weeks and be prone to error. 我的数据集大约有34000行,因此手动执行此操作可能需要数周的时间,并且容易出错。

Essentially I'm wondering if there is a way to take all the counts for each year/species/location combo and compare them to my datasheet detailing each year and location a count had taken place then for each location/year not found in the year/species/location combo add a row with the year/species/location and a count of 0. Ideally this would only be done for places where the species had been detected at some point over the 20 years of data. 本质上,我想知道是否有一种方法可以对每年/物种/位置组合进行所有计数,然后将其与我的数据表进行比较,详细说明每年和所发生位置的计数,然后对当年未找到的每个位置/年份进行计数/ species / location组合添加一行与year / species / location并计数为0。理想情况下,仅对在过去20年的数据中某个时刻检测到该物种的地方执行此操作。 Some species will never be found in certain areas so it's unnecessary to include a count for these places for those species. 在某些地区永远不会发现某些物种,因此没有必要为这些物种包括这些地方的数目。

Any help would be appreciated. 任何帮助,将不胜感激。

This can be done without adding fake data. 无需添加虚假数据即可完成此操作。 Set up a table for year, another table for location and one for species. 设置一张年份表,另一张表显示位置,一张表显示物种。 Add these three dimension tables and the count table to the Excel data model. 将这三个维度表和计数表添加到Excel数据模型。

Create relationships between the count table and the dimension tables. 在计数表和维度表之间创建关系。

在此处输入图片说明

Then build a pivot table with the year, species and location from the dimension tables instead of the count table. 然后使用维度表(而非计数表)中的年份,物种和位置构建数据透视表。 In the pivot table options, on the Display tab, select to show items with no data on rows and columns. 在数据透视表选项的“显示”选项卡上,选择显示行和列中没有数据的项目。 Now all the years, species and locations will show in the pivot table. 现在,所有年份,物种和位置都将显示在数据透视表中。 If a combination does not have a count, it will show empty. 如果一个组合没有计数,它将显示为空。

在此处输入图片说明

There might be a better solution to this but you can identify & replace the blank cells in a selected area using ' Go to ' function (shortcut: CTRL+G ) . 可能有更好的解决方案,但是您可以使用“ Go to ”功能(快捷键: CTRL+G )来标识并替换所选区域中的空白单元格

  1. You'll need to take a cell containing zero (0) and copy it. 您需要获取一个包含零(0)的单元格并将其复制。
  2. select the entire data block where you wish to replace blank cells with zeroes. 选择您希望用零替换空白单元的整个数据块。
  3. Press CTRL+G > select ' Blanks ' > OK . CTRL+G >选择“ Blanks ”>“ OK This will highlight all Blank cells in the selected area. 这将突出显示所选区域中的所有空白单元格。
  4. Then RIGHT CLICK on any one highlighted cell > Paste Special > Values (V) . 然后RIGHT CLICK任何突出显示的单元格> Paste Special > Values (V)

This would replace all the blanks with zeroes in your original sheet. 这会将原始工作表中的所有空白都替换为零。 You can then import this data wherever you want. 然后,您可以随时随地导入此数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM