-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyllable.py
42 lines (35 loc) · 1015 Bytes
/
syllable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
import numpy as np
import csv
import collections
dataset = pd.read_csv('try.csv')
ftCol = dataset.iloc[:, 0].values
def syllable_count(word):
word = word.lower()
count = 0
vowels = "aeiouy"
if word[0] in vowels:
count += 1
for index in range(1, len(word)):
if word[index] in vowels and word[index - 1] not in vowels:
count += 1
if word.endswith("e"):
count -= 1
if count == 0:
count += 1
return count+1
print(ftCol)
array = []
for j in range(3767):
array.append([syllable_count(i) for i in ftCol])
#print(array)
list1 = {'Names':array}
#print(list1)
df = pd.DataFrame(list1)
df_csv = pd.read_csv('try.csv')
#df_csv['syllable'] = df.Names # changed here
#df_csv.to_csv('withsyllable.csv', index=False, mode= 'w')
df_csv = pd.DataFrame(columns=['syllabe'])
for i in range(3767):
df_csv.loc[i] = [array[i][i]]
df_csv.to_csv('syllable.csv', index=False, mode= 'w')