### 第1關:統計每個城市的賓館平均價格
```
/********** Begin *********/
//1.獲取城市id
String cityId = Bytes.toString(result.getValue("cityInfo".getBytes(), "cityId".getBytes()));
byte[] value = result.getValue(family, column);
//獲取酒店價格
//String cityId1 = Bytes.toString(result.getValue("hotel_info".getBytes(), "price".getBytes()));
//將價格轉換為double
Double ho =Double.parseDouble(Bytes.toString(value));
//將價格轉換成()類型
DoubleWritable i = new DoubleWritable(ho);
String key = cityId;
//寫出(城市id,酒店價格)
context.write(new Text(key),i);
/********** End *********/
```
```
/********** Begin *********/
double sum=0;
int count=0;
for(DoubleWritable value:values){
count++;
sum+=value.get();
}
double avePrice=sum/count;
//創建pit對象
Put put =new Put(Bytes.toBytes(key.toString()));
put.addColumn("average_infos".getBytes(),"price".getBytes(),Bytes.toBytes(String.valueOf(avePrice)));
context.write(null,put);
/********** End *********/
```
### 第2關:統計酒店評論中詞頻較高的詞
```
/********** Begin *********/
byte[] value = result.getValue(family, column);
String word = new String(value,"utf-8");
if(!word.isEmpty()){
String filter = EmojiParser.removeAllEmojis(word);
List<Word> segs = WordSegmenter.seg(filter);
for(Word cont : segs) {
Text text = new Text(cont.getText());
IntWritable v = new IntWritable(1);
context.write(text,v);
}
}
/********** End *********/
```
```
/********** Begin *********/
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
Put put = new Put(Bytes.toBytes(key.toString()));
put.addColumn(family,column,Bytes.toBytes(sum));
context.write(null,put);
/********** End *********/
```