I'm new to Pandas and attempting to loop through a directory of 8 identically-structured .txt files on my local drive, put each one into its own Pandas DataFrame and then plot each one as its own subplot.
The files have no header, and look like this (but with a lot more rows):
0.01 100
0.02 150
0.03 225
Here is my Python code:
import glob
import pandas as pd
from matplotlib import pyplot as plt
path = '/path/to/data/files/2015*' #dir has 8 files beginning with 2015
files = glob.glob(path)
for file in files:
f = open(file, 'r')
df = pd.read_csv(f, sep=' ', header=None, )
fig = plt.figure(figsize=(10,8))
subs = plt.subplots(8, sharex=True)
df.plot(subplots=True)
plt.show()
What is weird is that it makes the structure of the 8 subplots, but it doesn't show any data plotted on them. Not sure why.
EDIT: I just noticed, when I read one of the files into a DataFrame as a test, it creates a df with the structure below:
0 0.01 100 N/A
1 0.02 150 N/A
2 0.03 225 N/A
It appears the code is adding N/A to each row as well as an index as the first column.