Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String in Pandas
#11
Wow thanks for the answers :)!!

But i thing that I wrong specify question.

In Yours examples you know that Goal is in First column ( names).

How to find in sheet Goal without know position? Example : 

Parameteres: Find( Goal or 19 in your example) in sheet.

return: Goal is in Second Row and in first Column[2,1] . 19 is in second row second column [2,2]

Pandas doesn have function .Find that returns me row and column


Thanks :)
Reply
#12
(Apr-07-2017, 12:46 PM)zivoni Wrote: If you need to find string in any colum, you will probably need to iterate over columns and checks each seperately.

(Apr-11-2017, 06:46 AM)yamanda Wrote: How to find in sheet Goal without know position? Example :
Output:
In [2]: df = pd.DataFrame({'col1':['foul', 'goal', 'pass'], 'col2':[1,3,2], 'col3':['goal', 'foul','goal 2'], 'col4':['foul', 'pass', 'foul'    ...: ]}) In [3]: df Out[3]:    col1  col2    col3  col4 0  foul     1    goal  foul 1  goal     3    foul  pass 2  pass     2  goal 2  foul In [4]: for column in df:    ...:     found = df[df[column].astype(str) == 'goal'].index    ...:     if len(found):    ...:         print(column, found.values)    ...:          col1 [1] col3 [0] In [5]: for column in df:    ...:     found = df[df[column] == 2].index    ...:     if len(found):    ...:         print(column, found.values)    ...:          col2 [2]
For string containing some substring you need to use .str.contains(). You can combine multiple conditions in selection, but you need to be careful about column types.
Reply
#13
Thanku i will try it.
how is it look like situation with finding position for numbers?

Oh Sorry i didnt see a example with number 2 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to search for specific string in Pandas dataframe Coding_Jam 1 2,415 Nov-02-2020, 09:35 AM
Last Post: PsyPy
  Parse XML String in Pandas Dataframe creedX 2 6,824 Dec-09-2019, 07:35 PM
Last Post: creedX
  pandas: can we look for the index of a string paul18fr 2 2,181 Jul-31-2019, 08:25 AM
Last Post: paul18fr
  Simple String to Time within a pandas dataframe Ecniv 1 2,480 Jun-14-2019, 03:25 AM
Last Post: scidam
  Converting string the pandas dataframe chrismc 0 2,333 Jan-24-2019, 11:07 AM
Last Post: chrismc

Forum Jump:

User Panel Messages

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