2121from __future__ import print_function
2222
2323import datacommons as dc
24- import pandas as pd
25-
26- import datacommons .utils as utils
27-
2824
2925def main ():
3026 # Set the dcid to be that of Santa Clara County.
3127 dcids = ['geoId/06085' ]
3228
3329 # Print all incoming and outgoing properties from Santa Clara County.
34- utils . _print_header ('Property Labels for Santa Clara County' )
30+ print ('Property Labels for Santa Clara County' )
3531 in_labels = dc .get_property_labels (dcids )
3632 out_labels = dc .get_property_labels (dcids , out = False )
3733 print ('> Printing properties for {}' .format (dcids ))
3834 print ('> Incoming properties: {}' .format (in_labels ))
3935 print ('> Outgoing properties: {}' .format (out_labels ))
4036
4137 # Print all property values for "containedInPlace" for Santa Clara County.
42- utils ._print_header (
43- 'Property Values for "containedInPlace" of Santa Clara County' )
38+ print ('Property Values for "containedInPlace" of Santa Clara County' )
4439 prop_vals = dc .get_property_values (
4540 dcids , 'containedInPlace' , out = False , value_type = 'City' )
4641 print ('> Cities contained in {}' .format (dcids ))
@@ -49,41 +44,13 @@ def main():
4944 print (' - {}' .format (city_dcid ))
5045
5146 # Print the first 10 triples associated with Santa Clara County
52- utils . _print_header ('Triples for Santa Clara County' )
47+ print ('Triples for Santa Clara County' )
5348 triples = dc .get_triples (dcids )
5449 for dcid in dcids :
5550 print ('> Triples for {}' .format (dcid ))
5651 for s , p , o in triples [dcid ][:5 ]:
5752 print (' - ("{}", {}, "{}")' .format (s , p , o ))
5853
59- # get_property_values can be easily used to populate Pandas DataFrames. First
60- # create a DataFrame with some data.
61- utils ._print_header ('Initialize the DataFrame' )
62- pd_frame = pd .DataFrame ({'county' : ['geoId/06085' , 'geoId/24031' ]})
63- print (pd_frame )
64-
65- # Get the names for the given counties.
66- utils ._print_header ('Get County Names' )
67- pd_frame ['county_name' ] = pd_frame ['county' ].map (
68- dc .get_property_values (pd_frame ['county' ], 'name' ))
69- pd_frame = pd_frame .explode ('county_name' )
70- print (pd_frame )
71-
72- # Get the cities contained in these counties.
73- utils ._print_header ('Get Contained Cities' )
74- pd_frame ['city' ] = pd_frame ['county' ].map (
75- dc .get_property_values (
76- pd_frame ['county' ], 'containedInPlace' , out = False , value_type = 'City' ))
77- pd_frame = pd_frame .explode ('city' )
78- print (pd_frame )
79-
80- # Get the names for each city.
81- utils ._print_header ('Get City Names' )
82- pd_frame ['city_name' ] = pd_frame ['city' ].map (
83- dc .get_property_values (pd_frame ['city' ], 'name' ))
84- pd_frame = pd_frame .explode ('city_name' )
85- print (pd_frame )
86-
8754
8855if __name__ == '__main__' :
8956 main ()
0 commit comments