I've done research and can't find anything that has solved my issue. I need a python script to read csv files using a folder path. This script needs to check for empty cells within a column and then display a popup statement notifying users of the empty cells. Anything helps!!
            Asked
            
        
        
            Active
            
        
            Viewed 625 times
        
    1
            
            
        - 
                    You don't need the overhead of `Panda` to do this. Python comes with a [CSV](https://docs.python.org/3/library/csv.html#module-csv) library that will allow you to do this. Use the `csv.reader()` to read the CSV file and then iterate over the output to check for empty cells. – Adrian Klaver Jul 15 '22 at 18:00
3 Answers
0
            
            
        Use the pandas library
pip install pandas
You can import the excel file as a DataFrame and check each cell with loops.
 
    
    
        LetsdothisEpic
        
- 126
- 1
- 6
0
            
            
        Hello I think it's quite easy to solve with pandas:
import pandas as pd 
df = pd.read_csv('<path>')
df.describe() # to  just see empoty stuff 
np.where(pd.isnull(df)) # to show indexes of empty celss -> from https://stackoverflow.com/questions/27159189/find-empty-or-nan-entry-in-pandas-dataframe
alternatively you can read the file and check line by line for empty cells
 
    
    
        partizanos
        
- 1,064
- 12
- 22
0
            
            
        A simple example using Python csv module:
cat test.csv                                                                                                                                                              
1,,test
2,dog,cat
3,foo,
import csv
with open('test.csv') as csv_file:
    empty_list = []
    c_reader = csv.DictReader(csv_file, fieldnames=["id", "fld_1", "fld_2"])
    for row in c_reader:
        row_dict = {row["id"]: item for item in row if not row[item]}
        if row_dict:
            empty_list.append(row_dict)
empty_list                                                                                                                                                                
[{'1': 'fld_1'}, {'3': 'fld_2'}]
This example assumes that there is at least one column that will always have a value and is the equivalent of a primary key. You have not mentioned what client you will be running this in. So it is not possible at this time to come up with a code example that presents this to the user for action.
 
    
    
        Adrian Klaver
        
- 15,886
- 2
- 17
- 28
