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!
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.
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.