-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaadhaar_data.py
More file actions
32 lines (28 loc) · 1.27 KB
/
aadhaar_data.py
File metadata and controls
32 lines (28 loc) · 1.27 KB
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
import pandas as pd
import pandasql
def select_first_50(aadhaar_data):
# Read in our aadhaar_data csv to a pandas dataframe. Afterwards, we rename the columns
# by replacing spaces with underscores and setting all characters to lowercase, so the
# column names more closely resemble columns names one might find in a table.
aadhaar_data.rename(columns = lambda x: x.replace(' ', '_').lower(), inplace=True)
# Select out the first 50 values for "registrar" and "enrolment_agency"
# in the aadhaar_data table using SQL syntax.
#
# Note that "enrolment_agency" is spelled with one l. Also, the order
# of the select does matter. Make sure you select registrar then enrolment agency
# in your query.
#
# You can download a copy of the aadhaar data that we are passing
# into this exercise below:
# https://s3.amazonaws.com/content.udacity-data.com/courses/ud359/aadhaar_data.csv
q = """
select registrar,enrolment_agency from aadhaar_data
LIMIT 50;
"""
#Execute your SQL command against the pandas frame
aadhaar_solution = pandasql.sqldf(q.lower(), locals())
return aadhaar_solution
if __name__=="__main__":
path='aadhaar_data.csv'
aadhaar_data=pd.read_csv(path)
print(select_first_50(aadhaar_data))