Do something interesting with python--Analyze QQ chat History

Source: Internet
Author: User

This is the case, there is a study of the elder sister Python, asked me how to deal with QQ chat record, then said the use of regular, nor to write, now idle (by the Ajax Abuse cry ...) Put it first) and write it briefly.

Goal, statistics in the last one months, QQ group in a day 24 time period of the number of speakers.

    STEP1: Get QQ chat record

    This is a simple no-brain ... Export the message record directly. See here for details. When exporting, remember to save it in txt format and place it in the same folder as the Python file (just for convenience).

    STEP2: Start the code

Environment: Python3+pycharm+xlsxwriter

    On the code:

Import Reimport xlsxwriter# gets 24 time periods----->time_list# used to fragment after time time_list = []for i in Range (0,24): # Here's the judgment used to turn a similar ' 8 ' To ' 08 ' to facilitate and export data matching if i < 10:i = ' 0 ' +str (i) else:i = str (i) time_list.append (i) # Create an Excel table and set the parameter Number workbook = Xlsxwriter. Workbook ('here is the name of the table. xlsx ') worksheet = Workbook.add_worksheet () worksheet.set_column (' A:a ', 5) worksheet.set_column (' b:b ', 10) # define a function,            Count each time period # times is a regular match to the "hour" data, in a list def everytime (i): num = 0 for time in times:if time = = I: num + = 1 print (i, '---> ', num) # Complete, write the data with the Write parameter: row, column, Data worksheet.write (int (i), 0, str (i) + "point") workshe Et.write (int (i), 1, NUM) # Open file, start matching "hours" data and Count save # Here remember to convert the code to Utf-8with open ("here is the TXT file name ", encoding= ' Utf-8 ') as F:data = F.read () # For example 20:50:52, to match the one of the PA = Re.compile (r "(\d\d): \d\d:\d\d") times = R E.findall (PA, data) for I in Time_list:everytime (i) # Remember to close the workbook workbook.close () print ("Finish, go to the folder and see the new . xlsx File Bar ")

Code comparison Ugly ... Please correct me.

The output is as follows:

After that, it's going to be visualized, well, Python's matplotlib is too big for me, so use Excel ...

  Step3:excel Visualization

  Visualization, well, in fact, is simply a line chart, 23333. For the line chart easy to observe, you can adjust the time before and after the order.

I come in this order: (the small amount of morning data on both sides)

At last:

This is the addition of the programming group, I would like to guess the figure bar, not responsible for guessing that ....

7 points to get up to work, the more near noon work more excited, noon after dinner to a nap, began an afternoon sleepy code work, finally boil to work, after dinner began a happy ... Yes or the code.

Diligent program staff, learning to 23 points, gradually a bit empty, well, go to bed, after all, tomorrow to work, but also to the code ... (This is a joke. 2333333)

Do something interesting with python--Analyze QQ chat History

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.