您好,我基本上是python的新手...我正在运行代码以根据条形图找出单词和情节的频率。
下面是代码:
lyrics="Ah, Ba Ba Ba Ba Barbara Ann Ba Ba Ba Ba Barbara Ann Oh Barbara Ann Take My Hand Barbara Ann You Got Me Rockin' And A-Rollin' Rockin' And A-Reelin' Barbara Ann Ba Ba Ba Barbara Ann ...More Lyrics... Ba Ba Ba Ba Barbara Ann Ba Ba Ba Ba Barbara Ann"
list_of_lyrics = lyrics.split(' ')
len(list_of_lyrics)
unique_words = set(list_of_lyrics)
len(unique_words)
word_histogram = dict.fromkeys(unique_words, 0)
for word in list_of_lyrics:
word_histogram[word] = word_histogram[word]+ 1
import plotly
from plotly.offline import iplot, init_notebook_mode
from plotly import tools
import plotly.graph_objs as go
init_notebook_mode(connected=True)
trace = {'type': 'bar', 'x': list(unique_words), 'y': list(word_histogram.values())}
plotly.offline.iplot({'data': [trace]})
输出为:
{'text/html': "<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>", 'text/vnd.plotly.v1+html': "<script>requirejs.config({paths: { 'plotly': }
答案 0 :(得分:1)
适用于Python3的解决方案:
static final int REQUEST_CODE = 1; // The request code
private void startFinishActivity() {
Intent intent = new Intent(this, FinishActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}