Python 转储twitter数据,尝试处理csv文件,程序运行,但不进行处理
因此,首先,我是python新手。我将数据从twitter直接转储到csv文件。然后,我希望使用程序读取该csv文件,并删除任何包含我未声明的信息的单元格。(在抓取数据时,您会收到许多不可用或不相关的信息)。代码不完整,但核心语法如下,我打算运行一个测试,看看它是否能满足我的要求。它运行程序并完成,但从未对现有的csvfile执行任何操作,我让它打开、读取和删除其中的单元格 我的问题是,有人看到代码有什么问题吗?除了它是未完成的,可以浓缩。我对python还只是一个星期的新手,并且在学习的过程中努力学习。如有任何反馈,将不胜感激Python 转储twitter数据,尝试处理csv文件,程序运行,但不进行处理,python,csv,twitter,Python,Csv,Twitter,因此,首先,我是python新手。我将数据从twitter直接转储到csv文件。然后,我希望使用程序读取该csv文件,并删除任何包含我未声明的信息的单元格。(在抓取数据时,您会收到许多不可用或不相关的信息)。代码不完整,但核心语法如下,我打算运行一个测试,看看它是否能满足我的要求。它运行程序并完成,但从未对现有的csvfile执行任何操作,我让它打开、读取和删除其中的单元格 我的问题是,有人看到代码有什么问题吗?除了它是未完成的,可以浓缩。我对python还只是一个星期的新手,并且在学习的过程中
import csv
f = open('csvdata.csv', 'r+', newline= '')
reader = csv.DictReader(f, fieldnames=None , dialect='excel')
x = 0
y = 0
for row in reader:
try:
cell = row[y][x]
if 'created_at' in cell:
x = x+1
elif 'id:' in cell:
x = x+1
elif 'text:' in cell:
x = x+1
####elif box starts with '':
####x = x+1
####continue
elif 'source:' in cell:
x = x+1
elif 'user:{' in cell:
x = x+1
elif 'name:' in cell:
x = x+1
elif 'screen_name:' in cell:
x = x+1
elif 'location:' in cell:
x = x+1
elif 'url:' in cell:
x = x+1
elif 'description' in cell:
x = x+1
elif 'translator_type:' in cell:
x = x+1
elif 'protected' in cell:
x = x+1
elif 'verified' in cell:
x = x+1
elif 'followers' in cell:
x = x+1
elif 'friends' in cell:
x = x+1
elif 'listed' in cell:
x = x+1
elif 'favourites' in cell:
x = x+1
elif 'statuses' in cell:
x = x+1
elif 'time' in cell:
x = x+1
elif 'lang:' in cell:
x = x+1
elif 'is_translator' in cell:
x = x+1
elif 'default_profile' in cell:
x = x+1
elif 'notification' in cell:
x = x+1
elif 'geo:' in cell:
x = x+1
elif 'coordinates:' in cell:
x = x+1
elif 'place:' in cell:
x = x+1
elif 'contributors:' in cell:
x = x+1
elif 'quoted_status' in cell:
x = x+1
elif 'retweeted_status' in cell:
x = x+1
else:
del_cell
x = x+1
except:
y = y+1
乍一看,您使用的是
DictWriter
,而不是DictReader
。然后,作为调试步骤,尝试在读取行时打印出行,以确保您实际读取的数据正确。该错误表示您仍在使用DictWriter
。当您使用DictReader
时,是否可以粘贴实际的错误消息?