# 数据整理

根据订单购买记录表，提取出一张用户基本信息表。

![](https://github.com/svcvit/excel_cursor_docs/blob/main/images/Xnip2024-09-13_20-03-14.jpg)

> 💡 通过 AI 理解哪些字段属于用户记录，自动推断需要保留的列，同时根据会员编码去重，即可达到目的

## 示例数据

| 交易时间                | 会员名称 | 会员性别 | 会员状态      | 会员编码           | 信息完整度 | 出生日期 | 可退换货数量 | 商品名称       | 商品编码     | 支付金额  | 最后购买时间     | 最后购买金额 | 来源渠道           | 标准售价  | 活跃度  | 累计购买次数 | 累计购买金额   | 订单编码     | 退货数量 | 销售净额  | 销售数量 |
| ------------------- | ---- | ---- | --------- | -------------- | ----- | ---- | ------ | ---------- | -------- | ----- | ---------- | ------ | -------------- | ----- | ---- | ------ | -------- | -------- | ---- | ----- | ---- |
| 2024-08-20 18:15:03 | 杭源垣  | 未知   | \[50]正式会员 | PP240321689842 | 0     |      | 2      | 维生素 AD 滴剂  | 12051054 | 91.60 | 2024-08-20 | 91.6   | 上海高济余天成大药房有限公司 | 45.80 | 活跃 A | 3      | 3,352    | 22859008 | 0    | 91.60 | 2    |
| 2024-08-20 18:00:26 | 宁媚如  | 男    | \[50]正式会员 | PP181127268580 | 0     |      | 1      | 甲磺酸溴隐亭片    | 22041774 | 90.50 | 2024-08-20 | 90.5   | 高济总部           | 90.50 | 活跃 A | 6      | 3,730.9  | 22858992 | 0    | 90.50 | 1    |
| 2024-08-20 15:09:14 | 蓬妤殉  | 女    | \[50]正式会员 | PP181127269347 | 0     |      | 1      | 萘敏维滴眼液     | 13186276 | 13.97 | 2024-08-20 | 30.2   | 一德泰和药房         | 13.97 | 活跃 A | 230    | 15,987.1 | 22858897 | 0    | 13.97 | 1    |
| 2024-08-20 15:09:14 | 蓬妤殉  | 女    | \[50]正式会员 | PP181127269347 | 0     |      | 1      | 复方醋酸地塞米松乳膏 | 13187858 | 16.23 | 2024-08-20 | 30.2   | 一德泰和药房         | 16.23 | 活跃 A | 230    | 15,987.1 | 22858897 | 0    | 16.23 | 1    |

## 提示词

```
这是一份用户订单数据，请根据表头识别哪些字段和用户基本信息相关，帮我整理出来，最终生成一张用户表，注意根据会员编码去重
```

## AI 回复内容

首先，根据用户的基本信息，我们可以识别出以下与用户相关的字段：

* 会员名称
* 会员性别
* 会员状态
* 会员编码
* 出生日期
* 信息完整度

接下来，通过这些字段生成一张用户表，并根据会员编码进行去重。以下是处理步骤：

1. 从原始数据中提取与用户基本信息相关的字段。
2. 根据会员编码去重，保留唯一的用户记录。

以下是实现这些步骤的 pandas 代码：

```python
import pandas as pd

user_columns = ['会员名称', '会员性别', '会员状态', '会员编码', '出生日期', '信息完整度']
df_users = data["CRM Data"][user_columns].drop_duplicates(subset='会员编码')
df_output = df_users.reset_index(drop=True)
```

## 结果

| 会员名称 | 会员性别 | 会员状态      | 会员编码           | 出生日期 | 信息完整度 |
| ---- | ---- | --------- | -------------- | ---- | ----- |
| 杭源垣  | 未知   | \[50]正式会员 | PP240321689842 | 0    |       |
| 宁媚如  | 男    | \[50]正式会员 | PP181127268580 | 0    |       |
| 蓬妤殉  | 女    | \[50]正式会员 | PP181127269347 | 0    |       |
| 苏丰宽  | 女    | \[50]正式会员 | PP181127269016 | 0    |       |
| 贺蓉凝  | 男    | \[50]正式会员 | PP181127265499 | 0    |       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coffbox.com/zh/shi-yong-shi-li/data-collation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
