Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Handy text processing in python, using pandas DataFrames.
This library is a python port of the R package tidytext.
pip install tidytext
This will also install the nltk package. However, you will need to download additional resources to use tidytext, using the code below.
nltk.download("punkt")
import pandas as pd
pd.set_option("display.max_rows", 6)
zen = """
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"""
zen_split = zen.splitlines()
df = pd.DataFrame({
"zen": zen_split,
"line": list(range(len(zen_split)))
})
df
zen | line | |
---|---|---|
0 | 0 | |
1 | The Zen of Python, by Tim Peters | 1 |
2 | 2 | |
... | ... | ... |
19 | If the implementation is hard to explain, it's a bad idea. | 19 |
20 | If the implementation is easy to explain, it may be a good idea. | 20 |
21 | Namespaces are one honking great idea -- let's do more of those! | 21 |
22 rows × 2 columns
from tidytext import unnest_tokens
unnest_tokens(df, "word", "zen")
line | word | |
---|---|---|
0 | 0 | NaN |
1 | 1 | the |
1 | 1 | zen |
... | ... | ... |
21 | 21 | more |
21 | 21 | of |
21 | 21 | those |
145 rows × 2 columns
from tidytext import unnest_tokens, bind_tf_idf
from siuba import _, count, arrange
(df
>> unnest_tokens(_.word, _.zen)
>> count(_.line, _.word)
>> bind_tf_idf(_.word, _.line, _.n)
>> arrange(-_.tf_idf)
)
line | word | n | tf | idf | tf_idf | |
---|---|---|---|---|---|---|
37 | 9 | counts | 1 | 0.500000 | 2.995732 | 1.497866 |
38 | 9 | readability | 1 | 0.500000 | 2.995732 | 1.497866 |
56 | 13 | explicitly | 1 | 0.333333 | 2.995732 | 0.998577 |
... | ... | ... | ... | ... | ... | ... |
99 | 18 | is | 1 | 0.125000 | 0.693147 | 0.086643 |
112 | 19 | is | 1 | 0.090909 | 0.693147 | 0.063013 |
124 | 20 | is | 1 | 0.076923 | 0.693147 | 0.053319 |
140 rows × 6 columns
FAQs
Text processing with pandas DataFrames.
We found that tidytext demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.