-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemover.py
121 lines (95 loc) · 3.34 KB
/
Remover.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 1 14:28:48 2022
@author: timothy
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 10 15:52:51 2022
@author: timothy
"""
#Remover adjusted
#dft = final_df.copy()
import pandas as pd
import numpy as np
def letter_in_word(df, letter):
#get the index of the words who contain the letter specified
index_words = []
for row in df.Set.iteritems():
index = row[0]
word_set = row[1]
if letter in word_set:
index_words.append(index)
df_new = df[df.index.isin(index_words)]
return(df_new)
#letter not in word
def letter_not_in_word(df, letter):
#get the index of the words who contain the letter specified
index_words = []
for row in df.Set.iteritems():
index = row[0]
word_set = row[1]
if letter in word_set:
index_words.append(index)
df_new = df[~df.index.isin(index_words)]
return(df_new)
#letter in position
def letter_in_position(df, letter, position):
'''
Parameters
----------
df : dataframe
Df with words, needs to at least have the set and list version of words.
letter : string
The letter you know the position of. Make sure to put it in ''
position : int
The position of the letter you know.
Returns a filtered df with only relevant words remaining
-------
'''
position = int(position)
index_words = []
for row in df.List.iteritems():
#get the word list and index seperated
word_list = row[1]
index = row[0]
#create a var that stores the letter of the word in the position we are interested in
#(I did position - 1 because python counts from 0 but thats not intuitive for entering)
letter_in_word = word_list[position -1 ]
#if the word letter in the specified position is equal to the one we are looking for, add the index to the list
if letter_in_word == letter:
index_words.append(index)
#create a filtered df with only relevant words remaining
df_new = df[df.index.isin(index_words)]
return(df_new)
#letter not in position
def letter_not_in_position(df, letter, position):
'''
Parameters
----------
df : dataframe
Df with words, needs to at least have the set and list version of words.
letter : string
The letter you know in which position it is not. Make sure to put it in ''
position : int
The position you know the letter is not in.
Returns a filtered df with only relevant words remaining
-------
'''
position = int(position)
index_words = []
for row in df.List.iteritems():
#get the word list and index seperated
word_list = row[1]
index = row[0]
#create a var that stores the letter of the word in the position we are interested in
#(I did position - 1 because python counts from 0 but thats not intuitive for entering)
letter_in_word = word_list[position -1 ]
#if the word letter in the specified position is equal to the one we are looking for, add the index to the list
if letter_in_word == letter:
index_words.append(index)
#create a filtered df with only relevant words remaining
df_new = df[~df.index.isin(index_words)]
return(df_new)