Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python for data Analysis

Shulou Source: shulou.com Published: 2022-06-02 19:21:44 09月19日 Update

This article mainly explains "how to use Python for data analysis", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use Python for data analysis" bar!

Comment on emotional tendency

First call Baidu AI to analyze the emotional tendency of Weibo and bilibili's comments.

Zhihu's answer is too many words, do emotional analysis is certainly not accurate, did not do the analysis.

From aip import AipNlp

"your APPID AK SK"

APP_ID = 'your APP_ID'

API_KEY = 'your API_KEY'

SECRET_KEY = 'your SECRET_KEY'

Client = AipNlp (APP_ID, API_KEY, SECRET_KEY)

Text = "XXXXXXXX"

"" invoke lexical analysis ""

Response = client.sentimentClassify (text)

# "sentiment": 2, / / indicates the classification result of emotional polarity 0: negative, 1: neutral, 2: positive

# "confidence": 0.40, / / indicates confidence of the classification

# "positive_prob": 0.73, / / indicates the probability of being in a positive category

# "negative_prob": 0.27 / / indicates the probability of being in a negative category

For info in response ['items']:

If info ['sentiment'] = = 2:

Print ("forward")

If info ['sentiment'] = = 0:

Print ("negative")

If info ['sentiment'] = = 1:

Print ("neutral")

Print ("credibility:", info ['confidence'])

Print ("the probability of being in the positive category is:", info ['positive_prob'])

Print ("the probability of being in the negative category is:", info ['negative_prob'])

It should be noted that "rush, back wave" is the most commented on each platform. It is a negative sentence in Baidu AI and needs special treatment.

The results are as follows:

Obviously, bilibili's on-screen comment is mostly positive, while Weibo's comments are mostly negative.

Word cloud

Through the emotional analysis above, users of different platforms have different attitudes towards "post-wave". How do they evaluate it?

Take a look at the high-frequency words in statistical comments and answers.

From scipy.misc import imread

From wordcloud import WordCloud, ImageColorGenerator

IsCN = 1 # 0: English participle 1: Chinese participle

Back_coloring_path = 'spray .jpg' # set the background image path

Text_path = 'reviews.txt' # sets the text path to be parsed

Stopwords_path = 'stop_word.txt' # disable the word list

Imgname1 = 'word cloud picture. PNG' # saved picture name 1 (only according to the shape of the background picture)

Back_coloring = imread (back_coloring_path) # set the background picture

Wc = WordCloud (# font_path = font_path # set font

Font_path='C:\ Windows\ Fonts\ simfang.ttf'

# font_path='hanyiqihei.ttf'

Background_color = 'white', # sets the background color

Max_words = 3000, # sets the maximum number of words displayed

Mask = back_coloring, # set the background picture

Max_font_size = 200,# sets the maximum font value

Min_font_size = 20, # set the font minimum

Random_state = 42, # there are random N color schemes

Width = 2000, height = 1720, margin = 4)

Words = {}

For i in word_counts:

Words ['{} '.format (I [0])] = I [1]

Wc.generate_from_frequencies (words)

# txt_freq example is {word1: fre1, word2: fre2, word3: fre3,., wordn: fren}

Plt.figure ()

bilibili

Zhihu

Thank you for your reading, the above is the content of "how to use Python for data analysis". After the study of this article, I believe you have a deeper understanding of how to use Python for data analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Analysis picture emotion background comment data data analysis probability category background picture font learning maximum neutral tendency content platform result path back wave Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology MySQL Redmi NVidia