Modification of dataframe values based on word lenght
0
0
Entering edit mode
3.2 years ago
Ratona • 0

Hi All,

I need to modify a dataframe. Here is the original dataframe:

word     frequency
W        20
ADK    3   
ADL    6
PO     4

If the length of the word in the 'word' column entry is larger than 1, and the letter 'A' is part of the entry, the script needs to divide the frequency by the number of letters in the word. Then, the product of the division needs to be added to the frequency of W. The end result should be:

word     frequency
W        23
ADK    3  
ADL    6
PO     4

Here is the code I wrote:

lettersList_A = ['A'] 

for index, row in df4.iterrows():
   if [i in row['word'] > 1 and not False in [i in lettersList_A for i in row['word']]
  df4.loc[df4.word == 'W', 'frequency'] = df4['frequency'] = df4.index + (len(i)/3)

It displays errors. Is the syntax correct?

Thanks a lot!

pandas python dataframe • 802 views
ADD COMMENT
0
Entering edit mode

I don't mean to embarrass you, but it is not clear why you deleted a similar question and created a new account just so you can ask the same question a bit differently. My recollection is that you had an answer already in that deleted thread. Hopefully you don't delete this one as well.

Also, it helps if you tell us what the error was so we don't have to guess.

ADD REPLY
0
Entering edit mode

Thank you for the heads up, Mensur. I've un-deleted this post as well as the other one.

Ratona, please do not delete posts that have received feedback.

ADD REPLY

Login before adding your answer.

Traffic: 2986 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6