pandas基础2

本文通过Pandas库对UFO和Pokemon数据集进行深入分析,展示了如何加载数据、数据清洗、特征工程及统计分析等过程,包括数据类型转换、条件筛选、分箱操作、索引设置及聚合计算等核心技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pandas基础2

先写练习题,明天再补知识点,好困,又是一个flag

1、(a)

df = pd.read_csv('data/UFO.csv')
df.rename(columns={'duration (seconds)':'duration'},inplace=True)
df['duration'].astype('float')
df.head()
df.query('duration > 60')['shape'].value_counts().index[0]

(b)

bins_long = np.linspace(-180,180,13).tolist()
bins_la = np.linspace(-90,90,11).tolist()
cuts_long = pd.cut(df['longitude'],bins=bins_long)
df['cuts_long'] = cuts_long
cuts_la = pd.cut(df['latitude'],bins=bins_la)
df['cuts_la'] = cuts_la
df.head()
df.set_index(['cuts_long','cuts_la']).index.value_counts().head()

2、(a)

df = pd.read_csv('data/Pokemon.csv')
df.head()
df['Type 2'].count()/df.shape[0]

(b)

df.query('Total >= 580')['Legendary'].value_counts(normalize=True)

(c)

df[df['Type 1']=='Fighting'].sort_values(by='Attack',ascending=False).iloc[:3]

(d)

df['range'] = df.iloc[:,5:11].max(axis=1)-df.iloc[:,5:11].min(axis=1)
attribute = df[['Type 1','range']].set_index('Type 1')
max_range = 0
result = ''
for i in attribute.index.unique():
    temp = attribute.loc[i,:].mean()
    if temp.values[0] > max_range:
        max_range = temp.values[0]
        result = i
result

(e)

df.query('Legendary == True')['Type 1'].value_counts(normalize=True).index[0]
attribute = df.query('Legendary == True')[['Type 1','Total']].set_index('Type 1')
max_value = 0
result = ''
for i in attribute.index.unique():
    temp = float(attribute.loc[i,:].mean())
    if temp > max_value:
        max_value = temp
        result = i
result
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值