【发布时间】:2021-11-29 21:10:43
【问题描述】:
我很难将 Excel 工作表中的非结构化数据转换为 Python 中的结构化表格格式,以便对其进行数据分析。
我想将位置(即巴黎)复制到 Col 4 到其相应的行。 # of x 下面的行代表一个人,可能会有所不同。例如,米兰有 3 个条目,而伦敦有 4 个。
此外,删除没有像 Paris 和 Rome 这样的条目的行。
我有点想法,但不知道如何实施。如果Col 2 不是# of Cafes to Visit 或不是数字,则将该值复制到Col 4 中,直到找到下一个条目...不过对此不确定:(
有人可以帮我吗?
输入:
| Col 1 | Col 2 | Col 3 | Col 4 |
|---|---|---|---|
| Location | Paris | ||
| # of Shops To Visit | # of Cafes to Visit | # of Museums to Visit | |
| Location | Milan | ||
| # of Shops To Visit | # of Cafes to Visit | # of Museums to Visit | |
| 3 | 5 | 3 | |
| 2 | 4 | 4 | |
| 5 | 6 | 7 | |
| Location | London | ||
| # of Shops To Visit | # of Cafes to Visit | # of Museums to Visit | |
| 6 | 6 | 2 | |
| 3 | 5 | 0 | |
| 5 | 4 | 1 | |
| 5 | 4 | 1 | |
| Location | Rome | ||
| # of Shops To Visit | # of Cafes to Visit | # of Museums to Visit |
输出:
| Col 1 | Col 2 | Col 3 | Col 4 |
|---|---|---|---|
| 3 | 5 | 3 | Milan |
| 2 | 4 | 4 | Milan |
| 5 | 6 | 7 | Milan |
| 6 | 6 | 2 | London |
| 3 | 5 | 0 | London |
| 5 | 4 | 1 | London |
| 5 | 4 | 1 | London |
【问题讨论】:
标签: python pandas data-transform