'python reading a csv file with panda and multiple filters
I want to read a csv with python and panda with multiple filters
example csv file with the name passwd.csv:
Funktion, Benutzer, Kennwort
user_p, user1, test1
user_f, user2, test2
user, bla, blup
python code:
import pandas
d = pandas.read_csv('C:\\tmp\\python\\passwd.csv')
res = d.query('Funktion == "user_f" ')
print (res)
this works fine
when I now changed the filter to 2 args, I got an error pandas.core.computation.ops.UndefinedVariableError: name 'User' is not defined
res = d.query('Funktion == "user_f" ') | d.query('Benutzer == "user2" ')
I can´t find the error
Kind regards Jens
Solution 1:[1]
I don't know if this is a typo, but you're trying to combine two dataframes (returned by query) with the | operator. It belongs in your expression:
res = d.query('Funktion == "user_f" | Benutzer == "user2" ')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tranbi |
