My problem is that I want to delete (' ') from the text output using the tooltip in folium within Python.
I wrote the following code to get the same output as above.
import pandas as pd
import folium #접근 불러오기, pandas = CSV파일을 불러오기 위한 모듈, folium = 지도 출력을 위한 모듈
sc = pd.read_csv("school4.CSV", encoding='cp949')
pu = pd.read_csv("puresection.CSV", encoding='cp949')
du = pd.read_csv("duplication2.CSV", encoding='cp949') #CSV파일 불러오기, 1:국내 대표 공과대, 2:정부출연연구기관, 3:2중 중복되는 위치
sc.dropna(inplace=True)
pu.dropna(inplace=True)
du.dropna(inplace=True) #불필요한 텍스트 제거(띄어쓰기 같은거)
pos = sc[["name","1st","2nd"]].values
gli = pu[["scname","right","left"]].values
tri = du[["t1","t2","t3","t4","t5"]].values #특정 열 불러오기
map=folium.Map(location=[36.365833333333335, 127.36361111111111],
zoom_start=8) #중심이 되는 위치, 카이스트
for data in pos:
folium.Marker([data[1], data[2]], #태그 위치, 프로그램에서는 번호시작을 0에서부터 시작한다. 자세한 내용은 CSV파일을 열어 대조하시오
tooltip=data[0], #커서가 닿았을시 data[0] 출력(학교 이름-영문자)
icon=folium.Icon(color="red") #아이콘 색상지정(아이콘의 모양과 색상 등을 지정할 수 있다.)
).add_to(map)#위 내용을 지도에 추가
for daat in gli:
folium.Marker([daat[1], daat[2]],
tooltip=daat[0],
icon=folium.Icon(icon="green")
).add_to(map)
for mate in tri:
plp = mate[0],mate[1],mate[2] #HERE!!!!!!!!!!
folium.Marker([mate[3], mate[4]],
tooltip=plp,
icon=folium.Icon(icon="green")
).add_to(map)
map.save("map3.html") #저장
map #지도 출력
But I got the following result:
So I asked a question because I want to remove (' ') from this output.
For reference, the CSV file here is this.
t1,t2,t3,t4,t5
KIET,KIEP,KLI,36.49444444,127.3047222
KIHASA,KRIVET,NYPI,36.495,127.3052778
KOTI,KEI,STEPI,36.495,127.3038889
Code
use join
& <br>
for reproducible example, use only du
& tri
in below code:
import pandas as pd
import folium
import io
txt = '''t1,t2,t3,t4,t5
KIET,KIEP,KLI,36.49444444,127.3047222
KIHASA,KRIVET,NYPI,36.495,127.3052778
KOTI,KEI,STEPI,36.495,127.3038889
'''
du = pd.read_csv(io.StringIO(txt), encoding='cp949')
tri = du[["t1","t2","t3","t4","t5"]].values
m = folium.Map(location=[36.365833333333335, 127.36361111111111], zoom_start=8)
for mate in tri:
plp = ',<br>'.join([mate[0], mate[1], mate[2]]) #HERE!!!!!!!!!!
folium.Marker([mate[3], mate[4]],
tooltip=plp,
icon=folium.Icon(icon="green")
).add_to(m)
m: