Python Forum

Full Version: Reading values into df.loc
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

First off I am very fresh to python and coding so apologies in advance.

I am trying to read values into a df.loc so that I can use an excel file to access the rows I want rather than manually typing them in each time. Currently, I have a basic line of code to change certain cells in a dataframe to another value.

df.loc[df.col1 == 'x', 'col2'] = 0
df.loc[df.col1 == 'y', 'col2'] = 0


I repeat this a bunch of times and currently, manually type in the cells in 'x'. Would it be possible to import values into x, y, z etc from another excel file?