import pyodbc
import pandas as pandas
def pd_readdb(query):
cn = pyodbc.connect('Driver={SQL Server};'
'Server=DESKTOP-O1H3HN2;'
'Database=ab;'
'Trusted_Connection=yes;')
pd_read = pandas.read_sql(query,cn)
return pd_read
cities = pd_readdb(" select * from [dbo].[worldcities]")
display(cities)
----------------------
import pandas as pd
cities = pd_readdb(" select * from [dbo].[worldcities]")
#fig, ax = plt.subplots(figsize =(10, 5))
cities = cities.query("country in ['India']")
import plotly.express as px
fig = px.line_mapbox(cities, lat="lat", lon="lng", color="country",labels = "population", text ="population",hover_name ="state and city",zoom=3, height=300)
fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_lat = 41,
margin={"r":0,"t":0,"l":0,"b":0})
fig.show(figsize =(10, 5))
----------------------------
import pandas as pd
cities = pd_readdb(" select * from [dbo].[worldcities]")
#fig, ax = plt.subplots(figsize =(10, 5))
cities = cities.query("country in ['India']")
import plotly.express as px
fig = px.line_mapbox(cities, lat="lat", lon="lng",
color="population",labels = {"population"},mapbox_style = "open-street-map",
text ="population",hover_name ="state and city",zoom=3, height=600)
fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_lat = 41,
margin={"r":0,"t":0,"l":0,"b":0})
fig.show(figsize =(10, 5))
-----------------------------------
import plotly.express as px
import pandas as pd
import numpy as np
cities = pd_readdb(" select * from [dbo].[worldcities]")
#fig, ax = plt.subplots(figsize =(10, 5))
cities = cities.query("country in ['India']")
fig = px.scatter_mapbox(cities, lat="lat", lon="lng", hover_name="country", hover_data=["state and city", "population"],
color_discrete_sequence=["fuchsia"], zoom=3, height=600)
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()