-1

Querying a pandas data frame using SQLite, I am wanting to select all rows that have a country cell entry of ''. So no characters in the cell. However, when I run the SQLite query I am getting no rows returned. Still new to Python.

Data frame structure:

  • Policy: object
  • Country: object
  • State: object

Data frame example:

Policy Country State
1 US NY
2 CA
3 US FL

SQLite select:

sqlcode = '''
Select
  [Policy],
  [Country],
  [State]
From
  sqldf
Where
  Country = ''
'''

check = psl.sqldf(sqlcode,locals())
CGarden
  • 169
  • 17

1 Answers1

1

Maybe the empty values on your column [Country] are actually NULL values. If you are trying to actually do a filter by empty values:

For example using:

sqlcode = '''
Select
  [Policy Reference],
  [Country],
  [State]
From
  sqldf
Where
  Country is null or Country = ''
'''

you can refer to this topic on stackoverflow -> SQLite select where empty?

MarcZ
  • 83
  • 8