在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):econpy/google-ngrams开源软件地址(OpenSource Url):https://github.com/econpy/google-ngrams开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):AboutHere you'll find a basic python script to retrieve data behind the trajectories plotted on the Google Ngram Viewer. A Python script that creates XKCD style plots from the ngram CSV data is also included, making it simple to create some awesome looking plots! Dependencies
UsageSimply type the same query you would type at the Google Ngram Viewer and retrieve the data in csv format. Quick Gotchas
Options
** This can be used with inflection, wildcard, and case-insensitive searches (otherwise it does nothing) where one column is the sum of some of the other columns (labeled with a column name ending in "(All)" or an asterisk for wildcard searches). In the Google Ngram Viewer, the columns whose sum makes up this column is viewable by right clicking on the ngram plot. In the ExamplesThere are tons of examples below that demonstrate of all kinds of available queries. Basic ExamplesHere are some basic example uses of
More Complicated ExamplesWildcard SearchesAs in the full Google Ngram Viewer, you can also perform wildcard searches using When doing a wildcard search, use the
Modifier SearchesModifier searches let you see how often one more modifies another word. The usual syntax for doing a modifier search is by using the Modifier searches can be done using
For more information on wildcard and modifier searches, take a look at the About Ngram Viewer page for more in depth documentation. Other Examples
Possible Corpora
PlottingThere are 2 easy ways to create your own plots using a CSV file produced by running a query with python getngrams.py railroad,radio,television,internet -startYear=1900 -endYear=2000 -caseInsensitive Plotting w/ xkcd.pyThe first way to create a plot is to use the supplied
python getngrams.py railroad,radio,television,internet -startYear=1900 -endYear=2000 -plot -caseInsensitive
python xkcd.py railroad_radio_television_internet-eng_2012-1900-2000-3-caseInsensitive.csv Both methods produce the same chart: Plotting w/ PandasAnother way to plot data from an ngram CSV file is to read the file into a pandas DataFrame object and call the .plot() option on it. Here we do that, but also convert the data to percentages first and add a title to the plot: from pandas import read_csv
df = read_csv('railroad_radio_television_internet-eng_2012-1900-2000-3-caseInsensitive.csv',
index_col=0,
parse_dates=True)
for col in df.columns:
df[col] = [i*100 for i in df[col]]
df.plot(title='Railroad, Radio, Television, and Internet') LicenseMIT License Moreover, PLEASE do respect the terms of service of the Google Ngram Viewer while using this code. This code is meant to help viewers retrieve data behind a few queries, not bang at Google's servers with thousands of queries. The complete dataset can be freely downloaded here. This code is not a Google product and is not endorsed by Google in any way. With this in mind... happy plotting! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论