Jun-05-2020, 09:20 AM
I am trying to make a regular express for df1(dataframe).
I want to remove the expression related NOPOP.NoPop and NONPOP information in 3rd column.
In order to achieve quick search, I put 3rd column as a index of dataframe.
And operated it in "df.filter" way with regex.
my desire output is just like below
I want to remove the expression related NOPOP.NoPop and NONPOP information in 3rd column.
In order to achieve quick search, I put 3rd column as a index of dataframe.
And operated it in "df.filter" way with regex.
import pandas as pd k=[['a','b','c','NOPOP'],['d','e','f','POP'],['g','h','i','j'],['k','l','m','Pop'],['n','o','p','NoPop_AA'],['q','r','s','NONPOP']] df_exp=pd.DataFrame(k) df1=df_exp.set_index([3]) df2=df1.filter(regex='[^NOPOP]|[^NoPop]|[^NONPOP]', axis=0)
Output:Out[263]:
0 1 2
3
NOPOP a b c
POP d e f
j g h i
Pop k l m
NoPop_AA n o p
NONPOP q r s
The result did not delete "NOPOP.NoPop and NONPOP" related information, why not? my desire output is just like below
Output: 0 1 2
3
POP d e f
j g h i
Pop k l m