Pandas return column value if other column value is equal
<p>so recentyl im trying to get data from CSV file using python and pandas.
Code should return or print data from colum 1 if data from column 2 is equal to some string. </p>

<pre><code>    import pandas as pd
df = pd.read_csv('alerts.csv', sep=';', encoding='latin1')

print(df[['color']['item']].loc[['color']=='red'])
</code></pre>

<p>but its seems not working with strings ?</p>

<p>you are not using .loc correctly</p>

<p>.loc need an indexer, and columns such has</p>

<pre><code>indexer = df[df['color']=='red'].index
print(df.loc[indexer,'item'])
</code></pre>

python csv pandas