You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何整理含多条目飓风的杂乱数据集以用于聚类分析

飓风数据集整理方案

核心思路

你的数据集里,每个飓风的名称存在time列的起始行,后续行是该飓风的逐时间记录。我们需要把飓风名称填充到对应记录行,再清理冗余列和无效行,最终得到聚类分析可用的格式。

具体代码实现(基于R语言)

先加载处理数据需要的包:

library(tidyverse)

然后对数据集做清洗和整理:

# 加载示例数据集(替换为你的实际数据集即可)
hurr <- structure(list(date_index = c("AL011851", "18510625", "18510625", 
"18510625", "18510625", "18510625"), time = c("            UNNAMED", 
" 0000", " 0600", " 1200", " 1800", " 2100"), n_entries = c("     14", 
"  ", "  ", "  ", "  ", " L"), type = c("", " HU", " HU", " HU", 
" HU", " HU"), wind = c(NA, 80L, 80L, 80L, 80L, 80L), Column5 = c("", 
" 28.0N", " 28.0N", " 28.0N", " 28.1N", " 28.2N"), Column6 = c("", 
"  94.8W", "  95.4W", "  96.0W", "  96.5W", "  96.8W")), row.names = c(NA, 
6L), class = "data.frame")

# 1. 提取并填充飓风名称:识别名称行后向下填充
hurr <- hurr %>%
  mutate(hurricane_name = ifelse(str_detect(time, "^\\s*\\d{4}$"), NA, str_trim(time))) %>%
  fill(hurricane_name, .direction = "down") %>%
  # 2. 过滤掉无有效记录的名称行
  filter(type != "") %>%
  # 3. 清理列结构与文本空格
  select(hurricane_name, type, wind, Column5, Column6) %>%
  mutate(across(c(hurricane_name, type, Column5, Column6), str_trim))

整理后的结果

运行代码后得到的数据集格式如下:

hurricane_name type wind Column5 Column6
1        UNNAMED   HU   80   28.0N   94.8W
2        UNNAMED   HU   80   28.0N   95.4W
3        UNNAMED   HU   80   28.0N   96.0W
4        UNNAMED   HU   80   28.1N   96.5W
5        UNNAMED   HU   80   28.2N   96.8W

该格式完全匹配你的期望输出,后续可直接用hurricane_name作为分组依据开展聚类分析。

内容的提问来源于stack exchange,提问作者Patrick Stephenson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 04:54:51