i dont know how exactly u got the error. if your columns just has two elemens as mentioned, it should work as shown below.
import pandas as pd
df = pd.DataFrame({'column':[[1,2,3,4,'',6,7],[2,3,'',5,6]]})
df['column'].apply(lambda x:x.remove(''))
print(df)
Output
column
0 [1, 2, 3, 4, 6, 7]
1 [2, 3, 5, 6]
the problem may happened because u may have an element which have no '' in it like [2,3,5,6] so in that case this error may occur. so just recreating the error we can see the same error happening.
import pandas as pd
df = pd.DataFrame({'column':[[1,2,3,4,'',6,7],[2,3,'',5,6],[2,3,5,6]]})
df['column'].apply(lambda x:x.remove(''))
print(df)
Error Output
Traceback (most recent call last):
File "C:/Users/Deva/PycharmProjects/IITJ/ML/MLf3/extras/adaf.py", line 3, in <module>
df['column'].apply(lambda x:x.remove(''))
File "C:\Users\Deva\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\series.py", line 3848, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas\_libs\lib.pyx", line 2329, in pandas._libs.lib.map_infer
File "C:/Users/Deva/PycharmProjects/IITJ/ML/MLf3/extras/adaf.py", line 3, in <lambda>
df['column'].apply(lambda x:x.remove(''))
ValueError: list.remove(x): x not in list
Solution For above situation
To avoid that just introduce try except
import pandas as pd
df = pd.DataFrame({'column':[[1,2,3,4,'',6,7],[2,3,'',5,6],[2,3,5,6]]})
try:
df['column'].apply(lambda x:x.remove(''))
except:
pass
print(df)
Output
column
0 [1, 2, 3, 4, 6, 7]
1 [2, 3, 5, 6]
2 [2, 3, 5, 6]