Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lambda functions
#1
Dear all,
I have a pandas dataframe and I created an extra column containing the string length of a record with

essay_cols=["record0", "record1"...] # where 'recordX' is the name of a column
all_essays = all_essays[essay_cols].apply(lambda x: ' '.join(x), axis=1) # I understand this joins all the words of the different columns in a single string
all_data["essay_len"] = all_essays.apply(lambda x: len(x)) # does this give the word count of a string or the length of a string?
But how can I make a field with the average word length and frequency of certain words?

I should count individual words in a string, get their length and divide them by the number of words. In the second case, I should retrieve specific words from a string and count them. And all as a lambda function. This is a bit beyond me.

Do you have any tips?...

Thank you

Luigi
Reply


Messages In This Thread
lambda functions - by Gigux - Feb-14-2019, 01:26 PM
RE: lambda functions - by scidam - Feb-15-2019, 12:18 AM
RE: lambda functions - by Gigux - Feb-15-2019, 09:10 AM
RE: lambda functions - by scidam - Feb-17-2019, 06:15 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020