Getting python script to run only from folder with files

  csv, pandas, path, python, xlsx

I have a python script which I would like to call csv and xlsx from a specific folder without having to specify the directory of each files needed to run the program.

import pandas as pd
df = pd.read_excel("WindDirectionWest2.xlsx")
df.drop(df.columns[df.columns.str.contains('unnamed',case = False)],axis = 1, inplace = True)
hey=df["WindDirection"].mean()
print(int(hey))
df = pd.read_excel("WindDirectionSouth2.xlsx")
df.drop(df.columns[df.columns.str.contains('unnamed',case = False)],axis = 1, inplace = True)
he=df["WindDirection"].mean()
print(int(he))
df = pd.read_excel("WindDirectionEast2.xlsx")
df.drop(df.columns[df.columns.str.contains('unnamed',case = False)],axis = 1, inplace = True)
he=df["WindDirection"].mean()
print(int(he))

So, I would like to have a code in top of my script calling a folder which then makes it redundant to write each file path to each code.

P.s I do not know how to put the code as python. I can only see Javascript, CSS, and HTML.

Source: Python Questions

LEAVE A COMMENT