Python Forum
pandas filter not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas filter not working
#1
I am trying to filter some info eg Name from a table and print it, but seems like my code is not working.
followed eg in  http://pbpython.com/excel-pandas-comp-2.html and still not working.

import pandas as pd
import numpy as np
all_dataB = pd.DataFrame()
dfB= pd.read_excel("C:\File2.xlsx")
dfB[dfB["BoardName"]=='Alex*']
all_dataB = dfB
print(dfB)#check
Reply
#2
Please explain not working.
How far do you get before a fail
Please post entire error traceback, it contains important information
Have you installed pandas?
Have you installed xlrd?
Have you checked to make sure a file named 'File2.xlsx' exists in C:\
Reply
#3

(Dec-28-2017, 11:58 AM)Larz60+ Wrote: Please explain not working.
How far do you get before a fail
Please post entire error traceback, it contains important information
Have you installed pandas?
Have you installed xlrd?
Have you checked to make sure a file named 'File2.xlsx' exists in C:\

modules are installed.
  [Image: eVR9NG]


i can print the result but it is not filtered, it was exactly same as input file. No errors message.
Reply
#4
tired on conda mini as well, code is not working.
Reply
#5
Could you attach a sample of File2.xlsx
so that it can be run here?
Reply
#6
(Jan-03-2018, 01:39 AM)Larz60+ Wrote: Could you attach a sample of File2.xlsx
so that it can be run here?
please try this
https://ufile.io/1i1sj
Reply
#7
anyone can help?~
Reply
#8
remove the c:\ fro m file name
import pandas as pd
import numpy as np


all_dataB = pd.DataFrame()
dfB= pd.read_excel("File2.xlsx")
dfB[dfB["BoardName"]=='Alex*']
all_dataB = dfB
print(dfB)#check
results:
Output:
Backend TkAgg is interactive backend. Turning interactive mode on. AreaName BoardName 0 Utopia Darren 1 Utopia Alex 2 Utopia Alex 3 Utopia Alex 4 Utopia Alex 5 Utopia Alex 6 Utopia Alex 7 Utopia Alex 8 Utopia Alex 9 Utopia Alex 10 Utopia Alex 11 Utopia Alex 12 Utopia Darren 13 Utopia Darren 14 Utopia Darren 15 Utopia Sean 16 Utopia MRRU 17 Utopia MRRU 18 Utopia MRRU 19 Utopia MRRU 20 Utopia MRRU 21 Utopia MRRU 22 Utopia Alex 23 Utopia Alex 24 Utopia Alex 25 Utopia Alex 26 Japan MRRU 27 Japan MRRU 28 Japan MRRU 29 Japan Alex .. ... ... 128 Japan MRRU 129 Japan MRRU 130 Indonesia Darren 131 Indonesia Alex 132 Indonesia Darren 133 Indonesia Darren 134 Indonesia Sean 135 Indonesia MRRU 136 Indonesia MRRU 137 Indonesia MRRU 138 Indonesia MRRU 139 Indonesia MRRU 140 Indonesia MRRU 141 Indonesia Alex 142 Indonesia Alex 143 Indonesia Alex 144 Indonesia Alex 145 Indonesia Alex 146 Indonesia Alex 147 Indonesia Alex 148 Indonesia Alex 149 Indonesia Alex 150 Indonesia Alex 151 Indonesia Alex 152 Indonesia Darren 153 Cebu Darren 154 Cebu Darren 155 Cebu Sean 156 Cebu Alex 157 Cebu MRRU [158 rows x 2 columns]
Reply
#9
(Jan-08-2018, 11:28 AM)Larz60+ Wrote: remove the c:\ fro m file name
 import pandas as pd import numpy as np all_dataB = pd.DataFrame() dfB= pd.read_excel("File2.xlsx") dfB[dfB["BoardName"]=='Alex*'] all_dataB = dfB print(dfB)#check 
results:
Output:
Backend TkAgg is interactive backend. Turning interactive mode on. AreaName BoardName 0 Utopia Darren 1 Utopia Alex 2 Utopia Alex 3 Utopia Alex 4 Utopia Alex 5 Utopia Alex 6 Utopia Alex 7 Utopia Alex 8 Utopia Alex 9 Utopia Alex 10 Utopia Alex 11 Utopia Alex 12 Utopia Darren 13 Utopia Darren 14 Utopia Darren 15 Utopia Sean 16 Utopia MRRU 17 Utopia MRRU 18 Utopia MRRU 19 Utopia MRRU 20 Utopia MRRU 21 Utopia MRRU 22 Utopia Alex 23 Utopia Alex 24 Utopia Alex 25 Utopia Alex 26 Japan MRRU 27 Japan MRRU 28 Japan MRRU 29 Japan Alex .. ... ... 128 Japan MRRU 129 Japan MRRU 130 Indonesia Darren 131 Indonesia Alex 132 Indonesia Darren 133 Indonesia Darren 134 Indonesia Sean 135 Indonesia MRRU 136 Indonesia MRRU 137 Indonesia MRRU 138 Indonesia MRRU 139 Indonesia MRRU 140 Indonesia MRRU 141 Indonesia Alex 142 Indonesia Alex 143 Indonesia Alex 144 Indonesia Alex 145 Indonesia Alex 146 Indonesia Alex 147 Indonesia Alex 148 Indonesia Alex 149 Indonesia Alex 150 Indonesia Alex 151 Indonesia Alex 152 Indonesia Darren 153 Cebu Darren 154 Cebu Darren 155 Cebu Sean 156 Cebu Alex 157 Cebu MRRU [158 rows x 2 columns]
my desire result should contains Alex only.
Reply
#10
import pandas as pd

all_datab = pd.DataFrame()
dfb = pd.read_excel("File2.xlsx")

dfc = dfb[dfb["BoardName"] == 'Alex']
print(dfc)
Results:
Output:
AreaName BoardName 1 Utopia Alex 2 Utopia Alex 3 Utopia Alex 4 Utopia Alex 5 Utopia Alex 6 Utopia Alex 7 Utopia Alex 8 Utopia Alex 9 Utopia Alex 10 Utopia Alex 11 Utopia Alex 22 Utopia Alex 23 Utopia Alex 24 Utopia Alex 25 Utopia Alex 29 Japan Alex 30 Japan Alex 31 Japan Alex 32 Japan Alex 33 Japan Alex 34 Japan Alex 35 Japan Alex 36 Japan Alex 37 Japan Alex 38 Japan Alex 39 Japan Alex 40 Japan Alex 52 Indonesia Alex 62 Indonesia Alex 63 Indonesia Alex .. ... ... 90 Utopia Alex 101 Utopia Alex 102 Utopia Alex 103 Utopia Alex 104 Utopia Alex 108 Japan Alex 109 Japan Alex 110 Japan Alex 111 Japan Alex 112 Japan Alex 113 Japan Alex 114 Japan Alex 115 Japan Alex 116 Japan Alex 117 Japan Alex 118 Japan Alex 119 Japan Alex 131 Indonesia Alex 141 Indonesia Alex 142 Indonesia Alex 143 Indonesia Alex 144 Indonesia Alex 145 Indonesia Alex 146 Indonesia Alex 147 Indonesia Alex 148 Indonesia Alex 149 Indonesia Alex 150 Indonesia Alex 151 Indonesia Alex 156 Cebu Alex [80 rows x 2 columns]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas replace function not working on datafram with floats bcrypto 1 3,765 Apr-12-2021, 08:59 PM
Last Post: bcrypto
  Python Custom Module not working in Jupyter Notebook with Pandas fid 0 2,331 Jul-04-2020, 11:05 AM
Last Post: fid
  Pandas + Groupby + Filter unique values JosepMaria 1 3,283 Jun-15-2020, 08:15 AM
Last Post: JosepMaria
  Pandas DF filter base on another DF Johnse 1 2,534 Sep-06-2019, 03:41 PM
Last Post: ThomasL
  import pandas as pd not working in pclinuxos loren41 3 2,841 May-19-2019, 03:49 PM
Last Post: Larz60+
  Working with date indexes (pandas) dervast 0 2,182 Apr-05-2019, 01:29 PM
Last Post: dervast

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020