Skip to content

Instantly share code, notes, and snippets.

View kipronokoech's full-sized avatar
🎯
Focusing

Kiprono Elijah Koech kipronokoech

🎯
Focusing
View GitHub Profile
# Morning Messaging
first = df.sort_values(by=["Date",'Time'],ascending=True).drop_duplicates(subset=['Date'])["Sender"].value_counts()
print(first)
plt.figure(figsize=(6,6))
plt.title("Morning Messages Count")
plt.bar(first.index,first)
plt.show()
#Late Night Messaging
last = df.sort_values(by=['Time'],ascending=False).drop_duplicates(subset=['Date'])["Sender"].value_counts()
# Count the number of messages per day by simply grouping by Date
gk = pd.DataFrame(df.groupby("Date").count()["Message"])
# plot results
time = list(gk.index)
number_of_messages = list(gk["Message"])
plt.figure(figsize=(12,10))
plt.axis("on")
plt.ylim(bottom=0,top=600)
plt.plot(time,number_of_messages)
# Calculate trend values
mv_average = gk["Message"].rolling(window=50, center=True, min_periods=3).mean()
#plot
plt.figure(figsize=(12,10))
plt.title("Number of Messages Per Day (With trend)")
plt.axis("on")
plt.ylim(bottom=0,top=600)
plt.plot(time,number_of_messages,label="Messages per day")
# plot vertical line for the time I travelled: Feb 2, 2020
# The most number of messsages in a day
maximum = gk[gk["Message"] == max(gk["Message"])]
print(maximum)
#the list number of messages in a day
minimum = gk[gk["Message"] == min(gk["Message"])]
print(minimum)
import string
mylove = []
myself = []
for i in range(len(df)):
if "My Wife, I LOVE YOU" in df.at[i,"Sender"]:
message = df.at[i,"Message"]
word_list = message.strip().lower().translate(str.maketrans('', '', string.punctuation)).split(" ")
for word in word_list:
if word not in (("a","and","the")):
from collections import Counter
#most common words
most_common_me = Counter(myself).most_common()
most_common_her = Counter(mylove).most_common()
print("Unique words used:")
print("Unique words She used: ",len(Counter(mylove).most_common()))
print("Unique words I used: ",len(Counter(myself).most_common()))
myself_common = []
common_count_me = []
for index, item in enumerate(most_common_me):
if index == 10:
break
myself_common.append(item[0])
common_count_me.append(item[1])
mylove_common = []
# Her most common words
common_her = pd.DataFrame(common_count_her,mylove_common,columns=["Her"]).sort_values(by="Her")
plt.figure(figsize=(8,6))
plt.barh(common_her.index, common_her["Her"], align='center', alpha=0.8,color="pink")
plt.yticks(mylove_common,mylove_common)
plt.xlabel('Words')
plt.title('Most Used Words(My Love)')
plt.show()
# Words I commonly used
import emoji
def extract_emojis(str):
return ''.join(c for c in str if c in emoji.UNICODE_EMOJI)
mylove_emojis = []
myself_emojis = []
for i in range(len(df)):
if "My Wife, I LOVE YOU" in df.at[i,"Sender"]:
message = df.at[i,"Message"]
#most common words
print("Most Common emojis used (Me)")
common_emojis_me = Counter(myself_emojis).most_common()
common_emojis_her = Counter(mylove_emojis).most_common()
emojis_me = []
count_me = []
for index, item in enumerate(common_emojis_me):
if index == 5:
break
print(item)