Apr-11-2017, 10:45 AM
(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.