This is a portion of my code:
df3 = pd.DataFrame(columns=["colA","colB"])
def someFunction(filePath,file,df):
df2 = pd.DataFrame(columns=["colA","colB"])
df1 = pd.read_csv(filePath,header=0)
var = ["foo1","bar1"]
df2['colA'] = ["foo2","bar2"]
df2['colB'] = var
df = df.append(df2)
df1 = pd.DataFrame()
df2 = pd.DataFrame()
return df
for root, dirs, fileList in os.walk(someDir):
for file in fileList:
if <someCondition>:
someFunction(filePath,file,df3)
print df3
On running the code, I don't see df2 getting appended to df3. Instead, the value of df3 within the function is the same as df3 and empty dataframe
outside the function.
How do I consistently append df2 to df3 and get df3 to grow for every file
processed?