【发布时间】:2018-10-03 13:12:38
【问题描述】:
我正在使用 pycharm 和 Python 3.7。
我想在 csv 中写入数据,但我的代码仅在文件中写入数据的第一行...有人知道为什么吗?
这是我的代码:
from pytrends.request import TrendReq
import csv
pytrend = TrendReq()
pytrend.build_payload(kw_list=['auto model A',
'auto model C'])
# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()
print(interest_over_time_df.head(100))
writer=csv.writer(open("C:\\Users\\
Desktop\\Data\\c.csv", 'w', encoding='utf-8'))
writer.writerow(interest_over_time_df)
【问题讨论】:
-
你确实看到你已经通过执行
writer.writerow而不是在循环中写入了一行代码。 -
@Pdf 你用的是哪个版本的python?
-
@pygo Python 3.7
-
好的,如果你和平时的
with open核对,那么试试我发布的可能有帮助的答案。
标签: python csv screen-scraping