Home > other >  Pandas the apply function problem
Pandas the apply function problem

Time:11-18

For I in df1 [' matching planner '] :
Print (I)
Dream a dream (no)
Meishan barack Obama (is) 1: meishan barack Obama, 2: meishan Paula, meishan jia hin, 3:
Leshan emei woman (no) 1: o hao Haoo, 2:3: dongya Idony ViviLee,

Applications for the data column function:
Def fou (s) :
For I in s:
If 'no' in I:
Return 'unused'
The else:
Return 'use'
Df1 [' matching planner ']. Apply (fou)
Results all:
Use 0
1 use
2 use the
Name: matching planner, dtype: object

But if change to elif 'is' I wouldn't have this problem in

But I use this test, print is right and is related to return?
For I in df1 [' matching planner '] :
If 'no' in I:
Print (1)
The else:
Print (2)

CodePudding user response:

Visual should be like this you want
 
Def fou (s) :
For I in s:
If 'no' in I:
Return 'unused'
Return 'use'

CodePudding user response:

Use 0
1 use
2 use the
Name: matching planner, dtype: object
0 unused
1 use
2 don't use
Name: matching planner, dtype: object
 the from pandas import DataFrame 
Def fou (s) :
For I in s:
If 'no' in I:
Return 'unused'
The else:
Return 'use'

Df1=DataFrame ({' matching planner: [' dream dream (no) ', 'meishan barack Obama (is) 1: meishan barack Obama, 2: meishan Paula, 3: meishan jia xin', 'leshan emei woman (n) 1: hao Haoo, o 2: ViviLee, 3: dongya Idony']})
Print (df1 [' matching planner ']. Apply (fou))
Def fou1 (I) :
If 'no' in I:
Return 'unused'
The else:
Return 'use'
Print (df1 [' matching planner ']. Apply (fou1))
  • Related