Home > other >  Apply method about dataframe overall change column value several questions!!
Apply method about dataframe overall change column value several questions!!

Time:01-13

(1) change the type of a column to STR, why want to use df [0]=df [0] astype (STR)
Using df [0]=df [0] apply (lambda x: STR (x))
Also do not complain, but line 1;
(2) I have a custom function:
Def aa (y) :
U=' ' ' ' 'this code in the text, to use regular expressions to extract time, etc.
Rerurn u

Then the column values using the apply method:
Df [0]=df [0] apply (lambda x: aa (x))
Always an error: "expected string or bytes - like object"
Here is a detail: I'm going to df [0] the first line of the assigned to the variable qq, qq dtype for STR, aa (qq) is to be able to run normally,
Then, I'll df_1 [0]=df [0] head (0), only take the line 1, with df_1 [0]=df_1 [0]. Apply (lambda x: aa (x)) is also wrong,
Help!!!!!!!!!!
  • Related