I am trying to filter a csv file from a column contains many minus numbers.
I found a source code on the website, which worked on small lists, but it does not work on data from a csv file.
here is an example of the data I have.
691
609
627
211
-226
921
829
1
972
173
181
-66
-96
573
and here is the code I am using
import pandas as pd
from pandas import DataFrame
import numpy as np
import re
import csv
from re import findall
ful = pd.read_csv(r'/home/aziz/Desktop/testminplus.csv')
ful1 = ful[0:]
#full = ['1', '-3']
full = ful1
regex = re.compile(r'(-\d*)')
# use only one of the following lines, whichever you prefer
#filtered = filter(lambda i: not regex.search(i), full)
filtered = [i for i in full if not regex.search(i)]
print(filtered)
The results are as the following:
[' ', ' ', ' ', ' ', '8', '2', '3', '\n', '0', ' ', ' ', ' ', ' ', '6', '0', '9', '\n', '1', ' ', ' ', ' ', ' ', '6', '2', '7', '\n', '2', ' ', ' ', ' ', ' ', '2', '1', '1', '\n', '3', ' ', ' ', ' ', '2', '2', '6', '\n', '4', ' ', ' ', ' ', ' ', '9', '2', '1', '\n', '5', ' ', ' ', ' ', ' ', '8', '2', '9', '\n', '6', ' ', ' ', ' ', ' ', ' ', ' ', '1', '\n', '7', ' ', ' ', ' ', ' ', '9', '7', '2', '\n', '8', ' ', ' ', ' ', ' ', '1', '7', '3', '\n', '9', ' ', ' ', ' ', ' ', '1', '8', '1', '\n', '1', '0', ' ', ' ', ' ', '6', '6', '\n', '1', '1', ' ', ' ', ' ', '9', '6', '\n', '1', '2', ' ', ' ', ' ', '5', '7', '3', '\n', '1', '3', ' ', ' ', ' ', '8', '9', '5', '\n', '1', '4', ' ', ' ', ' ', '1', '1', '8', '\n', '1', '5', ' ', ' ', ' ', ' ', '7', '\n', '1', '6', ' ', ' ', '6', '9', '8', '\n', '1', '7', ' ', ' ', ' ', '3', '5', '1', '\n', '1', '8', ' ', ' ', ' ', '9', '3', '3', '\n', '1', '9', ' ', ' ', ' ', '9', '3', '2', '\n', '2', '0', ' ', ' ', ' ', '7', '3', '2', '\n', '2', '1', ' ', ' ', '6', '6', '0', '\n', '2', '2', ' ', ' ', '4', '6', '5', '\n', '2', '3', ' ', ' ', ' ', '3', '4', '5', '\n', '2', '4', ' ', ' ', ' ', ' ', '1', '8', '\n', '2', '5', ' ', ' ', ' ', '1', '2', '0', '\n', '2', '6', ' ', ' ', '2', '7', '0', '\n', '2', '7', ' ', ' ', '2', '3', '3', '\n', '2', '8', ' ', ' ', '1', '5', '2', '\n', '2', '9', ' ', ' ', ' ', '1', '8', '6', '\n', '3', '0', ' ', ' ', '3', '9', '6', '\n', '3', '1', ' ', ' ', '5', '3', '5', '\n', '3', '2', ' ', ' ', ' ', '3', '5', '9', '\n', '3', '3', ' ', ' ', ' ', ' ', '1', '\n', '3', '4', ' ', ' ', '5', '3', '3', '\n', '3', '5', ' ', ' ', ' ', '8', '1', '2', '\n', '3', '6', ' ', ' ', ' ', '5', '4', '6']
The desired output is something like the following:
123
213
2
5
Any idea how to solve this problem?