-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.py
More file actions
46 lines (34 loc) · 939 Bytes
/
Copy pathsimple.py
File metadata and controls
46 lines (34 loc) · 939 Bytes
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
43
44
45
46
import pandas as pd
row = []
table = [[]]
filename = input('Enter the name of the text folder, eg buttonData.txt : ')
with open(filename, 'r') as file_object:
line = file_object.readline()
while line:
if line == '':
line = file_object.readline()
if line.startswith('[2018'):
timestamp = line[:19].strip('\n')
row.append(timestamp.strip('\n'))
line_remaining = line[20:].strip('\n').split(':')
sender = line_remaining[0].strip('\n')
row.append(sender.strip('\n'))
indx = line.find(sender) + len(sender)
row.append(line[indx:])
table.append(row)
else:
row.append(None)
row.append(None)
row.append(line)
table.append(row)
line = file_object.readline()
row = []
df = pd.DataFrame(table, columns = [
'Timestamp',
'Sender',
'Message'
])
df.fillna(method='ffill', inplace=True)
print(df)
csvname = input('Save csv with name: ')
df.to_csv(csvname, sep=',')