This example illustrates how to create a Dataset from a CSV file using pandas
import pandas
remote_file_path = 'http://data.sfgov.org/resource/wg3w-h783.csv'
df = pandas.read_csv(remote_file_path)
# Clean latitude and longitude values that are NaN
df = df[df.longitude == df.longitude]
df = df[df.latitude == df.latitude]
df.head()
incident_datetime | incident_date | incident_time | incident_year | incident_day_of_week | report_datetime | row_id | incident_id | incident_number | cad_number | ... | point | :@computed_region_6qbp_sg9q | :@computed_region_qgnn_b9vv | :@computed_region_26cr_cadq | :@computed_region_ajp5_b2md | :@computed_region_nqbw_i6c3 | :@computed_region_2dwj_jsy4 | :@computed_region_h4ep_8xdi | :@computed_region_y6ts_4iup | :@computed_region_jg9y_a9du | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | 2019-10-04T14:25:00.000 | 2019-10-04T00:00:00.000 | 14:25 | 2019 | Friday | 2019-10-04T16:13:00.000 | 85442603474 | 854426 | 190746203 | 192772728.0 | ... | POINT (-122.51129492624534 37.77507596005672) | 8.0 | 8.0 | 4.0 | 29.0 | NaN | NaN | NaN | NaN | NaN |
3 | 2019-10-03T19:30:00.000 | 2019-10-03T00:00:00.000 | 19:30 | 2019 | Thursday | 2019-10-03T23:25:00.000 | 85419706244 | 854197 | 190744514 | 192764437.0 | ... | POINT (-122.42746205880601 37.76877049785351) | 28.0 | 3.0 | 5.0 | 5.0 | 5.0 | NaN | NaN | NaN | NaN |
4 | 2019-10-04T16:53:00.000 | 2019-10-04T00:00:00.000 | 16:53 | 2019 | Friday | 2019-10-04T16:53:00.000 | 85446351040 | 854463 | 190746532 | 192772932.0 | ... | POINT (-122.5030864538133 37.781176766186576) | 6.0 | 8.0 | 4.0 | 29.0 | NaN | NaN | NaN | NaN | NaN |
5 | 2019-10-02T14:10:00.000 | 2019-10-02T00:00:00.000 | 14:10 | 2019 | Wednesday | 2019-10-02T22:59:00.000 | 85425706224 | 854257 | 196208142 | NaN | ... | POINT (-122.410497554147 37.80696290988273) | 99.0 | 6.0 | 3.0 | 23.0 | NaN | NaN | NaN | NaN | NaN |
6 | 2019-10-03T23:30:00.000 | 2019-10-03T00:00:00.000 | 23:30 | 2019 | Thursday | 2019-10-03T23:31:00.000 | 85422712030 | 854227 | 190744586 | 192764446.0 | ... | POINT (-122.417715898404 37.807978726080414) | 99.0 | 6.0 | 3.0 | 23.0 | NaN | NaN | NaN | NaN | NaN |
5 rows × 35 columns
from cartoframes.data import Dataset
ds = Dataset(df)
from cartoframes.viz import Map, Layer
Map(Layer(ds))