使用python处理来自Excel的数据

时间:2019-03-26 15:52:54

标签: python excel pandas matplotlib networkx

我的任务是使用python处理excel工作表中的数据,以使用networkx,panda和matplotlib显示交互式活动序列网络图。

网络图可是我互动的 箭头向生成节点的方向的每次更改,但都会反映在Excel工作表中 与之交互时,生成的网络图应能够显示每个节点的最短路由 每个节点应分配一个不同的代码。没有前任节点的节点,有一个前任节点的节点,有两个前任节点的节点等。 显示主控方向的箭头

我该如何编写脚本以同时生成实时时间表和网络图。

import xlrd
import networkx as nx
import numpy as np
import panda as pd
import matplotlib.pyplot as plt

#converting excel data to a dictionary

path = "path_to_my_excel_sheet"

workbook = xlrd.open_workbook(path)
workbook = xlrd.open_workbook(path, on_demand = True)
workbook = workbook.sheet_by_index(0)

headers = []
for col in range(worksheet.ncols):
headers.append(worksheet.cell_value(0. col))

for row in range(1, worksheet.nrows):
  elm = {}
  for col in range(worksheet.ncols):
  elm[headers[cols]] = worksheet.cell_value(row, col)
  return elm

#creating a panda data frame

df = pd.DataFrame(elm)
carc = pd.DataFrame(elm['Task_ID'], got stuck on how to proceed)

1 个答案:

答案 0 :(得分:0)

因此,您实际上可以使用read_excel()方法将excel工作表加载到Pandas中:

import pandas as pd
import numpy as np

df = pd.read_excel('OPT.xlsx')

完成数据框后,您实际上可以使用Pandas excel编写器将文件表写出来:

with pd.ExcelWriter("sampleFile.xlsx") as writer:
    df.to_excel(writer, sheet_name = 'sheet1') #or whatever sheetname you want here