-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremove_punctuation.py
More file actions
50 lines (37 loc) · 1.14 KB
/
remove_punctuation.py
File metadata and controls
50 lines (37 loc) · 1.14 KB
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
47
48
49
50
import csv
import pandas as pd
import string
review = pd.read_csv("C:/Users/mpink/OneDrive/Desktop/ai_fall2020/AI-Fall-2020/export1.csv")
#print(review.head(48))
exclude = set(string.punctuation)
def testRemove(sentence):
for ele in sentence:
if (ele in exclude):
sentence = sentence.replace(ele, "")
return sentence
# s = "hello. world!"
# xe = testRemove(s)
# print("Original String: ",s)
# print("Renewed String: ")
# print(xe)
# def remove_punctuation(x):
# testRemove(x)#
# x = ''.join(ch for ch in x if ch not in exclude)
# return x
# # Apply the function to the DataFrame
#review["reviewText"] = review["reviewText"].astype("|S")
actualReview = review["reviewText"]
#print(actualReview.head(48))
#review.reviewText = review.reviewText.apply(remove_punctuation)
#
for index, value in actualReview.items():
#print(f"Index : {index}, Review : {value}")
value = str(value)
value = testRemove(value)
print(value)
#print(actualReview.head(48))
#actualReview["reviewText"] = review['reviewText'].str.replace('[^\w\s]','')
#print(actualReview.head())
#checks
#print(review.dtypes)
#print(review.head(10))