Created
May 14, 2019 06:49
-
-
Save ayuLiao/c577499d89196e64eb4f2db44f7db657 to your computer and use it in GitHub Desktop.
使用 pandas 将 dict 转为 execl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
graph = {'A':{'A':0,'B':6,'C':INF,'D':6,'E':7}, | |
'B':{'A':INF,'B':0,'C':5,'D':INF,'E':INF}, | |
'C':{'A':INF,'B':INF,'C':0,'D':9,'E':3}, | |
'D':{'A':INF,'B':INF,'C':9,'D':0,'E':7}, | |
'E':{'A':INF,'B':4,'C':INF,'D':INF,'E':0} | |
} | |
import pandas as pd | |
# 字典转为 DataFrame | |
df = pd.DataFrame(graph).T # transpose to look just like the sheet above | |
df.to_csv('file.csv') | |
df.to_excel('file.xls') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment