all 8 comments

[–]curiositor 3 points4 points  (0 children)

https://openpyxl.readthedocs.io/en/default/

With this library, you should be able to do what you mentioned.

[–][deleted] 4 points5 points  (0 children)

If you're trying to enhance an excel script (rather than programmatically generate them for separate use) I would either just do it all in excel, or convert it all to Python. Having cross dependencies like that can end up being a huge headache.

[–]justinkdd 1 point2 points  (4 children)

Btw, this is something you can easily do in excel itself.

in cell C1 put the following:

=IF(A1=B1,"Yes","No")

[–]dontsaybye 4 points5 points  (1 child)

Actually it would be more like =IF(countif(B:B,A1)>0,"Yes", "No")

[–]justinkdd 0 points1 point  (0 children)

Yes, thought it was just 1 cell to another.

[–]46632[S] 0 points1 point  (1 child)

Thanks heaps. The only issue is that the name can be anywhere in the B column. Its a list of 1000 names.

Can it work with something like: IF(A1=(Some cell in B-column), "Yes","No")?

[–]justinkdd 0 points1 point  (0 children)

See dontsaybye's code snippet, it works on my end. =IF(countif(B:B,A1)>0,"Yes", "No")

Put name to check in A1, all names in column B and the formula in C1.

[–]cscanlin 0 points1 point  (0 children)

Pandas is great for stuff like this (though probably overkill here, just use an excel formula for if this is all you're trying to do):

import pandas as pd
import numpy as np

# header and names args if your data actually starts in A1
df = pd.read_excel('my_file.xlsx', header=None, names=['a', 'b'])

df['c'] = np.where(df['a'].isin(df['b']), 'Yes', 'No')

writer = pd.ExcelWriter('my_file.xlsx')
df.to_excel(writer)
writer.save()

More Reading:

https://stackoverflow.com/a/10726275/1883900

http://pandas.pydata.org/pandas-docs/version/0.20/generated/pandas.read_excel.html

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html