简体   繁体   中英

Replace em dash with hyphen while reading excel files in Python using Pandas

i am reading an excel file using panda data frames. Column names may contain hyphen or em dash. i would like to replace all em dash with hyphen so that i can read column values with hyphen. row ['abc-def'].

连字符或破折号,您仍然可以读取列(字符串是字符串!),但是如果您坚持要这样做,可以使用以下方法来解决破折号:

df.columns = [c.replace("–", "-") for c in df]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM