简体   繁体   English

如何在excel中转​​置数据

[英]How to transpose data in excel

I have a data set like the following in r (several thousands of artworks), a screenshot is also attached.我在r中有一个如下的数据集(几千件艺术品),还附上了截图。

A            B

1              Pierre Bonnard

Title          La rue, Orgue de Barbarie    
Medium         oil on canvas
Year of Work       1911
Size           Height 63.2 cm.; Width 89.8 cm.
Sale of        Sotheby's New York: Friday, May 30, 2014 [Lot 00018]
               Impressionist & Modern Art Including Russian Art
Sold For    293,000 USD Premium

2             Eugene Berman

Title         Dormenas, statue et campanile
Medium          oil on canvas
Year of Work     1932
Size           Height 92.1 cm.; Width 73 cm.
Sale of        Sotheby's New York: Friday, May 30, 2014 [Lot 00086]
              Impressionist & Modern Art Including Russian Art
Sold For      12,500 USD Premium

I would like to transpose the dataset like the following one:我想转置数据集,如下所示:

artist    title    medium   year.of.work   size   sale.of   sold.for
Pierre    ...
...

I have tried the transpose function in excel, but it is not working properly.我在excel中尝试了转置功能,但它无法正常工作。在此处输入图片说明

Transpose isn't going to do it for the data that you have. Transpose 不会为您拥有的数据执行此操作。

Unfortunately, some of your data values seem to be spread over more than one cell, that makes it a bit more of a problem, but not insuperable.不幸的是,您的某些数据值似乎分布在多个单元格中,这使其成为一个更大的问题,但并非不可克服。

Let's deal with the case first where the data values are always in a single cell.让我们首先处理数据值总是在单个单元格中的情况。 From the limited sample of data that would seem to be the attributes such as Artist, Title, Medium, Year of Work, Size, Misc., Estimate and Sold For.从有限的数据样本来看,似乎是艺术家、标题、媒介、工作年份、尺寸、杂项、估计和售出等属性。

  1. Put all the headers required in your output list in a convenient row either below the existing data or on another worksheet.将输出列表中所需的所有标题放在现有数据下方或另一个工作表上的方便行中。

  2. Next select all the data in Column A of your original data set (from cell A3 down to the "Sold For" of the last painting).接下来选择原始数据集 A 列中的所有数据(从单元格 A3 到最后一幅画的“已售出”)。

  3. Apply a data filter to this Selection (Data tab on ribbon, Filter Button).将数据过滤器应用于此选择(功能区上的“数据”选项卡,“过滤器”按钮)。

  4. Filter the selection in column A by clicking the down arrow in cell A3 and, when the drop-down appears, unselect the "Select All" option and then select "Title" in the list of check boxes.通过单击单元格 A3 中的向下箭头过滤 A 列中的选择,当下拉列表出现时,取消选择“全选”选项,然后在复选框列表中选择“标题”。 Your data will now be filtered so that all entries in column A have value "Title" and column B shows the titles of the paintings, starting with "La rue, Orgue de Barbarie".现在将过滤您的数据,以便 A 列中的所有条目都具有值“标题”,而 B 列显示画作的标题,以“La rue, Orgue de Barbarie”开头。

  5. Select all the titles showing in column B and Copy to the clipboard.选择 B 列中显示的所有标题并复制到剪贴板。 Paste the selection to the cell immediately below the "Title" header created as part of Step 1. You've now got the Title column in your output.将所选内容粘贴到作为步骤 1 的一部分创建的“标题”标题正下方的单元格中。现在您的输出中有标题列。

  6. Go back to the drop down in A. Select a different attribute, by unchecking "Title" and selecting eg "Medium".返回到 A 中的下拉列表。通过取消选中“标题”并选择例如“中”来选择不同的属性。 Col B will now have the values of the new attribute. Col B 现在将拥有新属性的值。 Copy and paste to your output list.复制并粘贴到您的输出列表。 Repeat this step until all the attributes whose values are always contained in a single cell data have been added to the output list.重复此步骤,直到其值始终包含在单个单元格数据中的所有属性都已添加到输出列表中。

The artists can be selected by selecting all the numeric values in the drop-down - probably easiest to check "Select All" then uncheck the non-numerics.可以通过选择下拉列表中的所有数值来选择艺术家 - 可能最容易选中“全选”然后取消选中非数字。 Or if you feel adventurous you could try using a number filter from the drop down options which show above the list of checkboxes.或者,如果您喜欢冒险,您可以尝试使用显示在复选框列表上方的下拉选项中的数字过滤器。

The data values spread over multiple cells need processing so that each data value is contained within a single cell.分布在多个单元格中的数据值需要处理,以便每个数据值都包含在单个单元格中。 This is fairly straightforward but involves use of a few formulas.这相当简单,但涉及使用一些公式。

  1. Make sure the "Select All" option is checked on the Data Filter on Column A确保在 A 列的数据过滤器上选中“全选”选项
  2. In cell D3 add the following formula =AND(NOT(ISBLANK(B4)),ISBLANK(A4))在单元格 D3 中添加以下公式=AND(NOT(ISBLANK(B4)),ISBLANK(A4))
  3. Copy this formula down all cells in column D (cell D3 downwawrds to the end of your original data).将此公式向下复制 D 列中的所有单元格(将单元格 D3 向下复制到原始数据的末尾)。 The values in column D are now either TRUE or FALSE . D 列中的值现在是TRUEFALSE TRUE indicates that the data value in column B continues in the cell below. TRUE表示 B 列中的数据值在下面的单元格中继续。
  4. In cell C3 add the formula =B2 and in cell C4 add the formula =IF(D4,B4&C5,B4) .在单元格 C3 中添加公式=B2并在单元格 C4 中添加公式=IF(D4,B4&C5,B4) Copy the formula in C4 down the rest of column C so that all your original data is covered.将 C4 中的公式复制到 C 列的其余部分,以便覆盖所有原始数据。 The values in Column C are either 0 (if nothing in Col B) or the value in Column B (if the data is not continued in cell below) or the value in column B along with any continuation cells (if the value in column B is continued in the cell below). C 列中的值是 0(如果 B 列中没有任何内容)或 B 列中的值(如果数据不在下面的单元格中继续)或 B 列中的值以及任何连续单元格(如果 B 列中的值在下面的单元格中继续)。 The formulas in Column C cater for the possibility that a data value might be spread over more than 2 cells in column B (though the sample data does not show any doing so). C 列中的公式满足了数据值可能分布在 B 列中 2 个以上单元格的可能性(尽管示例数据没有显示任何这样做)。

Having got your data into shape its now pretty much as before EXCEPT having selected a data type which may spread over multiple cells such as "Description" in previous step 4., select the cells with the data values from column C rather than column B AND use Paste Values rather just Paste when applying previous step 5.使您的数据成形后,现在几乎和以前一样,除了在前面的步骤 4 中选择了可能分布在多个单元格上的数据类型(例如“描述”)之外,从 C 列而不是 B 列中选择具有数据值的单元格在应用前面的步骤 5 时,使用粘贴值而不是粘贴。

If you can follow what's going on above then you could put the formula into Cols C and D first and then copy the data values exclusively from column C (remembering that Paste Values is required rather than just Paste).如果您可以按照上面发生的事情进行操作,那么您可以先将公式放入 C 列和 D 列中,然后仅从 C 列复制数据值(请记住,需要粘贴值而不仅仅是粘贴)。

There is an underlying assumption in the above that each attribute (such as Title, Description, etc) required in your output appears once and only once in column A against each painting.上面有一个基本假设,即输出中所需的每个属性(例如标题、描述等)在 A 列中针对每幅画仅出现一次且仅出现一次。 This looks to be the case from the limited sample of data, but if it isn't then the output data will be misaligned across rows.从有限的数据样本来看,这似乎是这种情况,但如果不是,那么输出数据将跨行错位。 eg if the Title for picture 5 is missing in the original data then what shows in the output as the titles for picture 5 will that of picture 6, title of picture 6 will be that of picture 7, etc.例如,如果原始数据中缺少图片 5 的标题,那么输出中显示的图片 5 的标题将是图片 6 的标题,图片 6 的标题将是图片 7 的标题,等等。

There are other ways of getting to your end result, which use formulas to detect the position of each data item in column B and which then make use of the =INDIRECT and =ADDRESS functions, but the approach above is probably simpler and easier to understand.还有其他方法可以获得最终结果,它们使用公式来检测 B 列中每个数据项的位置,然后使用=INDIRECT=ADDRESS函数,但上述方法可能更简单,更容易理解.

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

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