이승우
이승우

Reputation: 7

I want to convert uppercase words to lowercase in dataframe and put them below

  1. convert uppercase to lowercase
  2. add below it.
en ko
Acceptive Acceptive koean mean
Access Access koean mean

=>

en ko
Acceptive Acceptive koean
acceptive Acctptive koean
Access Access koean
access Accesskoean

please help !!!!!!!

Upvotes: 0

Views: 51

Answers (2)

jaemmin
jaemmin

Reputation: 341

I guess the input is like this form.

>>> df
      en  ko
0  Apple  사과
1    Ant  개미

First, repeat the rows.

>>> df2 = df.loc[df.index.repeat(2)].reset_index(drop = True)
>>> df2
      en  ko
0  Apple  사과
1  Apple  사과
2    Ant  개미
3    Ant  개미

Now, you can lower the odd rows.

>>> for row in range(len(df)):
...     df2.loc[2*row+1].en = df2.loc[2*row+1].en.lower()

>>> df2
      en  ko
0  Apple  사과
1  apple  사과
2    Ant  개미
3    ant  개미

Upvotes: 1

Алексей Р
Алексей Р

Reputation: 7627

First, we convert each element of the en column into a list containing the same text in original and lower case. Then we use explode() to "unpack" the values of the list into different strings

df.en = df.en.apply(lambda x: [x,x.lower()])
df = df.explode('en',ignore_index=True)
print(df)

The same in one line:

df = df.assign(en=lambda y: y.en.apply(lambda x: [x, x.lower()])).explode('en',ignore_index=True)
          en                    ko
0  Acceptive  Acceptive koean mean
1  acceptive  Acceptive koean mean
2     Access     Access koean mean
3     access     Access koean mean

Upvotes: 1

Related Questions