根据列值创建多个数据框

时间:2019-03-22 14:04:54

标签: python pandas

我有一个包含3列的数据框。我想基于列StoreCountryName的值创建多个数据框。数据框dataset的示例如下所示。

+----------------------+--+------------------+--+------------------+
|     ReceiptCode      |  | ItemCategoryName |  | StoreCountryName |
+----------------------+--+------------------+--+------------------+
|  0000P70322000039467 |  |  Wrapping        |  |   Japan          |
|  0000P70322000031468 |  |  Kitchen         |  |   Germany        |
|  0000P70322000031467 |  |  Food            |  |   Germany        |
|  0000P70322000032267 |  |  Kitchen         |  |   Japan          |
|  0000P70322000031467 |  |  Food            |  |   Denmark        |
|  0000P70322000031867 |  |  Food            |  |   Denmark        |
|  0000P70322000051467 |  |  Interior        |  |   Germany        |
|  0000P70322000087468 |  |  Kitchen         |  |   Switzerland    |
|  0000P70322000031469 |  |  Leisure         |  |   Germany        |
|  0000P70322000031439 |  |  Food            |  |   Switzerland    |
+----------------------+--+------------------+--+------------------+

我希望每个StoreCountryName值的结果是

print(dataset_Denmark)

    +----------------------+--+------------------+--+------------------+
    |     ReceiptCode      |  | ItemCategoryName |  | StoreCountryName |
    +----------------------+--+------------------+--+------------------+
    |  0000P70322000031467 |  |  Food            |  |   Denmark        |
    |  0000P70322000031867 |  |  Food            |  |   Denmark        |
    +----------------------+--+------------------+--+------------------+

还可以自动将数据框命名为dataset+'_Country',即dataset_Denmark吗?

0 个答案:

没有答案