[英]How to read every row of CSV and invoke the value by a user function, and then save the result in an csv file?
import csv
import time
with open("AuthorName.csv", "rb") as f:
reader = csv.reader(f, delimiter="\t")
for line in enumerate(reader):
time.sleep(2)
print line[1]
The result is like:结果是这样的:
['rhaf_hq']
['Digixp']
['bujhoapp']
['styhuang']
['mkasanm']
How can I invoke these lists in the function below: Screen_names如何在下面的函数中调用这些列表: Screen_names
print json.dumps(get_user_profile(twitter_api, screen_names=["SocialWebMining"]), indent = 1 )
Here's a sample function that seems to do what you asked.这是一个示例函数,它似乎可以满足您的要求。 It works as follows:
它的工作原理如下:
. .
import csv
def make(fileName):
with open(fileName) as file:
values = []
#Putting all your file's data in a list
for each in file:
each = each.strip()
values.append(each)
#Creating your new file
with open('newValues.csv','w') as newFile:
#creating a variable to write with
valueWriter = csv.writer(newFile)
#writing each individual value to your new file
for each in values:
valueWriter.writerow([each])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.