for i in tweets_df.ix[:,0]:
if regex_getter(i) != None:
city,state = regex_getter(i).split(',')
print(city,state)
我基本上只是想把城市和州写成csv。打印城市和州打印正好我下面的内容减去标题
我的csv应该看起来像
City State
Burlington VT
Minneapolis MN
Bloomington IN
Irvine CA
答案 0 :(得分:1)
您可以使用csv
模块执行此操作:
writerow
将采用迭代,并在单独的列中编写iterable中的每个项目。
import csv
....
with open("test.csv", "w", newline='') as csvfile:
writer = csv.writer(csvfile)
#write header, or something
for i in tweets_df.ix[:,0]:
if regex_getter(i) != None:
data = regex_getter(i).split(',')
writer.writerow(data)