python提取数据指定列_Python:提取特定列数据并将其存储到变量中

我有一个csv文件,我想从中提取ratings和comments字段,并将其存储在两个变量中-rating和comment。这个过程完成后,我需要查看提取的数据。CSV文件中存储的数据如下:

9fe53cb6005edd4344e08c7a9ebfe78d.png

在我的dataclean python文件中,目前编写的代码是:class Extractdata:

def __init__(self, rating, comment):

self.rating = rating

self.comment = comment

requirement_list = []

import csv

with open('D://Python//testml//my-tracks-reviews.csv', encoding='utf-8') as fileread:

filereader = csv.DictReader(fileread, delimiter=';', quotechar='"')

next(filereader, None) # Skip the header.

# Unpack the row directly in the head of the for loop.

for rating, comment_text in filereader:

# Get the data in the variable instances.

rating = int(rating)

comment = comment_text

# Now create the requirement instance and append it to the list.

requirement_list.append(Extractdata(rating, comment))

# View the data

我得到了以下错误:

^{pr2}$

也可以有人建议如何从这个文件在另一个文件访问评级变量主.py计算平均收视率?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值