Last active
March 27, 2025 15:51
-
-
Save sebington/9f59f2e2d0b5dc433fc148b4fe32f2e7 to your computer and use it in GitHub Desktop.
Mon premier script en Python !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script is destined to be executed in a directory containing a series of files with a 'yyyymmdd' naming pattern | |
# e.g. "20240621_212441.wav". The script will parse the date in each filename and plot the number of files per year-month. | |
import os | |
import fnmatch | |
import matplotlib.pyplot as plt | |
# create empty list | |
list1=[] | |
# select only .wav file names in current folder and populate the list | |
for file_name in os.listdir(): | |
if fnmatch.fnmatch(file_name, '*.wav'): | |
list1.append(file_name) | |
# filter list1 by selecting 'yyyymm' and populate list2 | |
list2=[] | |
for date in list1: | |
list2.append(date[0:6]) | |
# count the number of occurences of dates per month and generate a list of tuples | |
from collections import Counter | |
word_counts = Counter(list2) | |
frequency = word_counts.most_common() | |
# sort by date and print to double-check | |
frequency.sort() | |
print("Message frequency per month:") | |
print(frequency) | |
# plot the number of messages per month over the entire range | |
x, y = zip(*frequency) | |
plt.bar(x, y) | |
plt.ylabel("number of messages") | |
plt.xlabel("year") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment