Loading and displaying dataframes from multiple files in python -
i trying read in multiples files directory , assign different variables using loop. when run script doesn't output results:
import pandas pd import os os.chdir("~pathtodirectory") file1="baseball.csv" file2="baseball1.csv" output=dict() x=0 file in [file1,file2]: output[x]=pd.read_csv(file) output[x].head() x=+1
first of all, should using enumerate
. secondly, should calling print
.
for i, file in enumerate([file1, file2]): output[i] = pd.read_csv(file) print(output[i].head()) # <------------
if keys going indices, why not use list instead?
output = [] file in [file1, file2]: output.append(pd.read_csv(file)) ...
Comments
Post a Comment