AnsweredAssumed Answered

Excel cell value as variable?

Question asked by vonmoosa on Oct 23, 2018
Latest reply on Oct 23, 2018 by vonmoosa

I'm trying to pull cell values from the files I'm grabbing in the code below so I can write them in the loop for a new column. The column will be called ADT and their value is in cell A333.

import os, sys, pandas as pd

path = r"C:\Users\anthonyv\Downloads\Metro\New folder"

files = os.listdir(path)

data = []  # a list to hold your data

for filename in files:
    f = filename.split(' MP ')
    address = f[0]
    mile = '.'.join(f[1].split(' ')[0].split('_')) # convert underscore to period
    df = pd.DataFrame({'MP': ["{}".format(mile)],'RdNm': ["{}".format(address)]})
    data.append([address, mile])

df = pd.DataFrame(data,columns=['Road','Milepost'],dtype=float)
writer = pd.ExcelWriter('MetroReportAGOL.xlsx')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()

print ("Complete")

Outcomes