I am trying to import a set of *.txt files. I need to import the files into successive columns of a Pandas DataFrame in Python.
Requirements and Background informati
You're very close. ijk
is the filename already, you don't need to access the list:
# Step 3: Build up DataFrame:
df = pd.DataFrame()
for ijk in filelist:
frame = pd.read_csv(ijk)
df = df.append(frame)
print df
In the future, please provide working code exactly as is. You import from pandas import *
yet then refer to pandas as pd, implying the import import pandas as pd
.
You also want to be careful with variable names. files
is actually a single file path, and filelist
and filesList
have no discernible difference from the variable name. It also seems like a bad idea to keep personal documents in your python directory.