A few things:
filenames = glob.glob(path + "/*.csv")
-- unless I'm wrong, that should be a backslash, not a forward-slash. Forward slashes are primarily used in Unix systems, etc. but definitely not in Windows where path names are concerned.Try printing out
filename
. It will give you the whole path as well. At thedf.to_csv
line, you're actually writing topath + filename + transposed + Tr + filename
. You have to isolate the specific filename (usingsplit
or theos
module may work).
I'm using Ubuntu, so this might not apply that accurately, but here's how I'll do it.
import pandas as pd
from glob import glob
path = "/home/nanashi/Documents/Python 2.7/Scrapers/Scrapy/itbooks"
filenames = glob(path + "/*.csv")
for filename in filenames:
specname = filename.split("/")[-1]
print filename
print specname
dfs = pd.read_csv(filename)
df = dfs.transpose()
df.to_csv("transposed/%s" % specname)
Result:
/home/nanashi/Documents/Python 2.7/Scrapers/Scrapy/itbooks/realestateau.csv
realestateau.csv
/home/nanashi/Documents/Python 2.7/Scrapers/Scrapy/itbooks/itbooks.csv
itbooks.csv
[Finished in 0.6s]
Screenshot of transposed file:
Let us know if this helps.