搜狐笔试题记录(以后要把考过的题记下来,万一再考一遍呢,自己却忘了!!!)

import pandas as p

    1.SQL题就是利用窗口函数然后套娃 加一个查询

2.python题

# 搜狐数据
    raw_data = {'platform': ['pcnews', 'pcnews', 'pcnews', 'pcnews', 'news', 'news', 'news', 'news', 'video', 'video', 'video', 'video'],
            'order_num': ['1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd','1st', '1st', '2nd', '2nd'],
            'comment': [523, 52, 25, 616, 43, 234, 523, 62, 62, 73, 37, 35],
            'uv': [1045, 957, 1099, 1400, 1592, 1006, 987, 849, 973, 1005, 1099, 1523]}


    # Q1: 读入数据,到一个dataframe命名为content,并且将其中的列名作为dataframe的column index
    
import pandas as pd
content=pd.DataFrame(raw_data)

    # Q2: 筛选所有order_num = '2nd' 且platform = 'news'


 content[(content['order_num']=='2nd') & (content['platform']=='news')]


    # Q3: 筛选content的第2-4行和第2列之后的数据


content.iloc[1:4,2:]


    # Q4: 对content进行分组计算,按照platform 和order_num 对comment 求和 并按照求和结果进行降序排列


content['comment'].groupby([content['platform'],content['order_num']]).sum()

    # Q5: 新生成一列变量为 rank,评价标准为,当platform='news'且 comment >= 70时 rank = 'good', 当platform='pcnews'且 comment >= 500时 rank = 'medium', 其他 rank = 'worse'


def function(platform,comment):
    if 'new' in platform and comment>=70:
        rank='good'
    elif 'pcnews' in platform and comment>=500:
        rank='medium'
    else :
        rank='worse'
    return rank


content['rank']=content.apply(lambda x: function(x.platform,x.comment),axis=1)
print(content)


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值