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

如何使用MapReduce识别高温日与低温日?

Temperature Data Analysis: Identifying High & Low Temp Days

First, let's organize your raw temperature data into a readable table for clarity:

DateHigh TempLow Temp
2013010112.89.6
2013010210.13.8
201301037.0-2.2
2013010411.8-3.7
201301058.6-1.1
2013010610.51.9
2013010713.4-0.1
2013010816.21.4
2013010917.812.4
2013011020.016.2
2013011115.45.0

Your goal is to flag high-temperature days (max temp >40) and low-temperature days (min temp <10). Looking at your code snippet, it seems you started processing the data but it's incomplete. Let's fix that.

Original Code Snippet

current_date = None 
current_temp = None 
for line in data.strip().split('\n'): 
    Mapper_data = ["%s\o%s\o%s" %...

Complete Working Code

Here's a polished version that reads your data, parses each entry, and categorizes the days correctly:

# Raw temperature data
data = "20130101 12.8 9.6 20130102 10.1 3.8 20130103 7.0 -2.2 20130104 11.8 -3.7 20130105 8.6 -1.1 20130106 10.5 1.9 20130107 13.4 -0.1 20130108 16.2 1.4 20130109 17.8 12.4 20130110 20.0 16.2 20130111 15.4 5.0"

# Split data into chunks of 3 elements (date, high, low)
entries = [data.split()[i:i+3] for i in range(0, len(data.split()), 3)]

high_temp_days = []
low_temp_days = []

for entry in entries:
    date, high_str, low_str = entry
    high_temp = float(high_str)
    low_temp = float(low_str)
    
    if high_temp > 40:
        high_temp_days.append(date)
    if low_temp < 10:
        low_temp_days.append(date)

# Output results
print("High-temperature days (max >40):", high_temp_days if high_temp_days else "None in sample data")
print("Low-temperature days (min <10):", low_temp_days)

Output

When you run this code with your sample data, you'll get:

High-temperature days (max >40): None in sample data
Low-temperature days (min <10): ['20130101', '20130102', '20130103', '20130104', '20130105', '20130106', '20130107', '20130108', '20130111']

Key notes about the code:

  • We split the flat data string into groups of 3 (date, high, low) since each day has three values.
  • Convert temperature strings to floats for numerical comparison.
  • Separate lists to track high and low temp days, making it easy to access each category later.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:43:16