How to reduce all elements in a pandas data frame?

Just a question guys, I have a pandas dataframe:

In [11]: df = pd.DataFrame([['A', 'B'], ['C', E], ['D', 'C']],columns=['X', 'Y', 'Z']) In [12]: df Out[12]: XYZ 0 ABD 1 CEC 

How can I convert to omit all df elements:

 Out[12]: XYZ 0 abd 1 cec 

I am looking at the documentation and I have tried the following:

 df = [[col.lower() for col in [df["X"],df["Y"], df["Z"]]]] df 

However, it does not work. How to omit all elements inside pandas dataframe ?.

+6
source share
1 answer

Or

 df.applymap(str.lower) Out: XYZ 0 abd 1 cec 

or

 df.apply(lambda col: col.str.lower()) Out: XYZ 0 abd 1 cec 

The first is faster and it looks better, but the second can handle NaN.

+15
source

Source: https://habr.com/ru/post/1011828/


All Articles