Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

python - Marking my place in a CSV during a project

I have a project where I am going through a list of emails and making a change to a database. The issue is that I won't be able to do it all at once(i need to break this up into multiple runs). But I also don't want to overlap emails I already processed.

The emails are filled in from a CSV. I want to loop through each email and if the process was successful want to mark a column with "X". This way I can have my program make sure not to use emails with "x"s next to them. Then export it to the same file so I won't have to make any changes the next time I run.

I am having trouble with the logic though.

changes = ['[email protected]', '[email protected]']

if data['emails'] in changes:

data = pd.read_csv('data.csv')

###process goes here and exports list of processed emails in changes

changes = ['[email protected]', '[email protected]']
if data['emails'] in changes:
    data['processed'] = "x"
data.to_csv('data.csv')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Put the CSV in a data frame and add a “marking” column to the data frame. Add a 1 or an x to the correct row in the data frame anytime the email is used. You can use the index to know how to mark the x. Ie you are in column Email index 5, you then would append an X in column “indicator” index 5.

pseudo code

x = 0
for x in range (y):
    df.[“Email”].iloc[x]
    df.insert(x, “indicator”, “x”

When you’re done export to a csv and overwrite the pervious file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...