一个基于PySpark的大数据分析小项目

二手车交易数据分析

课程作业做的一个数据分析的小项目,主要基于pyspark和pandas库,使用python3.11

数据来自datafoundation的一份有2000条数据的数据集

为了寻求品牌与价格间的关系,所以首先写了一段程序用于从“leixing”列中的具体车型提取出品牌名存为新的一列。
import pandas as pd
import re

def extract_brand(car_name):
    # Use regex to extract the brand (first word) from the car name
    match = re.match(r'^([\u4e00-\u9fff]+|\w+)', car_name)
    if match:
        return match.group(1)
    return ''

# Read the CSV file
df = pd.read_csv('guazi.csv', encoding='utf-8')

# Create a new column 'brand' by extracting the brand from 'leixing'
df['brand'] = df['leixing'].apply(extract_brand)

# Save the updated DataFrame to a new CSV file
df.to_csv('guolv.csv', index=False, encoding='utf-8')

print("Brand extraction complete. New file created.")

得到新的一个数据表如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值