Pandas query function not working with spaces in column names

前端 未结 5 953
-上瘾入骨i
-上瘾入骨i 2020-11-30 10:45

I have a dataframe with spaces in column names. I am trying to use query method to get the results. It is working fine with \'c\' column but getting error for \

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 11:35

    I am afraid that the query method does not accept column name with empty space. In any case you can query the dataframe in this way:

    import pandas as pd
    a = pd.DataFrame({'a b':[1,2,3,4], 'c':[5,6,7,8]})
    a[a['a b']==1]
    

提交回复
热议问题