Monday, 15 September 2014

python - UndefinedVariableError when querying pandas DataFrame -


I am trying to create a graph by querying values ​​in Pando DataFrame .

In this line:

  data 1 = [np.query ('type == i') ['continuous'] i ('type' 1 ',' Type 2 ',' Type 3 ',' Type 4 ']]  

I get an error:

  Unchanged Variable error: Name 'I' is not defined  

What am I missing?

i in your query expression

  df.query ('type == i')  

Really just string 'i' is there is no extra insert quote , So Panda interprets it as the name of any other column in your DataFrame , that is, it looks for those cases where

  df ['type'] Since there is no  i  column, you get an  unchanged variable error .  

P>

It looks like the value in the type column is equal to the string variable name i , that is where

  Df ['type'] == 'Type1' df ['type'] == 'Type2' # etc  

In this case, you really need to put string i in the query expression:

df.query ('type == "% S" '% i)

Extra set of quotes are required if ' Type1 ', ' type2 ' etc. Value within the type column, but if they are not the names of other columns, the dataframe.


No comments:

Post a Comment