I am attempting to create a bit of code that will apply a function on each row of a specific database column. Other posts I have seen appear to apply a function over the row of all columns, which is not what I need.
What I have attempted to do is to subset the data to get a database with only the column I need ('blargh' in script below), and then try to churn the database through a for loop. However, I'm not sure how to iterate over each row. Could someone help me by understanding how to make the for loop below function?
import pandas as pd
import os.path
# Get the path to the demos directory.
base_path = os.path.dirname(__file__)
text_file = pd.read_csv(os.path.join(base_path, "names.txt"), sep = '; ' , engine='python')
# subsetting
blargh = text_file[["Name"]]
print(blargh)
# attempting to make a for loop
for row in blargh:
print(row)
Edit: As requested, here is the background for why I am attempting this. This is an attempt to fix a problem I was investigating in an earlier post but I haven't made any worthwhile progress. Click here to see the original problem
Essentially, I am attempting to use the package pylabels to create printable name tags. The original code uses a txt file where every row is a name. I wish to add more details to the nametags, so I am attempting to modify the code to take in a database and add the appropriate information to each label. The original script had this code:
with open(os.path.join(base_path, "names.txt")) as names:
sheet.add_labels(name.strip() for name in names)
where sheet = labels.Sheet(specs, write_name, border=True). When I attempted to modify this to:
with text_file[["Name"]] as names:
sheet.add_labels(name.strip() for name in names)
I got a AttributeError: __exit__. Someone suggested using try/finally statement, but I can't seem to get it to work.
(full error:
Traceback (most recent call last):
File "sticker.V.7.py", line 173, in <module>
with text_file[["Name"]] as names:
AttributeError: __exit__
)
applya function to the column data? Or just print it out? If print, see the flagged duplicate