how can I plot data from a list against its indices using a for loop?
(I need do write something because my post is mostly code and I have dot add some more details...)
This is the code sample:
import pandas as pd
import os
import matplotlib.pyplot as plt
import numpy as np
path = r'D:\Experiments\20210924_SureliteOPO_beampointing\all_log'
filesnames = os.listdir(path)
filesnames = [f for f in filesnames if (f.startswith("2") and f.lower().endswith(".csv"))]
dfs = list() # a list of dataframes
for csvfile in filesnames:
fpath = path '/' csvfile
df = pd.read_csv(fpath, skiprows=26, skipfooter=5)
dfs.append(df)
print(dfs)
The output looks like this:
[ Powermeter1 Start
0 0.001864
1 0.001756
2 0.001818
3 0.001837
4 0.001932
.. ...
95 0.001697
96 0.001950
97 0.001871
98 0.001757
99 0.001849
[100 rows x 1 columns], Powermeter1 Start
0 0.001771
1 0.001863
2 0.001796
3 0.001885
4 0.001746
.. ...
95 0.001827
96 0.001678
97 0.001813
98 0.001776
99 0.001637
[100 rows x 1 columns]], ...
...
...
Regards,
Karl
CodePudding user response:
found it:
for i in range(len(dfs)):
plt.plot(df.index,dfs[i])
CodePudding user response:
enumerate()
is designed for when you need to loop over an iterable's elements with access to their indices:
for i, elem in enumerate(dfs):
...