【发布时间】:2020-05-06 11:47:20
【问题描述】:
我有以下 csv 格式的数据
Date,State,City,Station Code,Minimum temperature (C),Maximum temperature (C),Rainfall (mm),Evaporation (mm),Sunshine (hours),Direction of maximum wind gust,Speed of maximum wind gust (km/h),9am Temperature (C),9am relative humidity (%),3pm Temperature (C),3pm relative humidity (%)
2017-12-25,VIC,Melbourne,086338,15.1,21.4,0,8.2,10.4,S,44,17.2,57,20.7,54
2017-12-25,VIC,Bendigo,081123,11.3,26.3,0,,,ESE,46,17.2,53,25.5,25
2017-12-25,QLD,Gold Coast,040764,22.3,35.7,0,,,SE,59,29.2,53,27.7,67
2017-12-25,SA,Adelaide,023034,13.9,29.5,0,10.8,12.4,N,43,18.6,42,27.7,17
VIC 的输出应该是
S : 1
ESE : 1
SE : 0
N : 0
但是我得到的输出是
S : 1
ESE : 1
因此想知道,如何使用唯一函数来包含其他 2 个缺失的结果。下面是调用 csv 文件的程序
import pandas as pd
#read file
df = pd.read_csv('climate_data_Dec2017.csv')
#marker
value = df['Date']
date = value == "2017-12-26"
marker = df[date]
#group data
directionwise_data = marker.groupby('Direction of maximum wind gust')
count = directionwise_data.size()
numbers = count.to_dict()
for key in numbers:
print(key, ":", numbers[key])
【问题讨论】:
-
我真的很难理解你在这里想要做什么!特别是您的代码对您提供的数据样本没有产生任何结果。您能否进一步详细说明您正在尝试做什么?