0

I have a pandas dataframe that holds the file path to .wav data. Can I use pandas DataFrame.plot() function to plot the data referenced?

Example:

typical usage: df.plot()

what I'm trying to do: df.plot(df.path_to_data)???

I suspect some combination of apply and lambda will do the trick, but I'm not very familiar with these tools.

anon01
  • 10,618
  • 8
  • 35
  • 58
  • If you want to plot data through `df.plot`, it needs to be in memory. Alternatively, see this link which offers an alternative with `pylab`: https://stackoverflow.com/a/11249430/4909087 – cs95 Dec 17 '17 at 09:36

2 Answers2

1

No, that isn't possible. plot is first order function that operates on pd.DataFrame objects. Here, df would be the same thing. What you'd need to do is

  1. Load your dataframe using pd.read_* (usually, pd.read_csv(file)) and assign to df
  2. Now call df.plot

So, in summary, you need -

df = pd.read_csv(filename)
... # some processing here (if needed)
df.plot()

As for the question of whether this can be done "without loading data in memory"... you can't plot data that isn't in memory. If you want to, you can limit tha number of rows you read, or you can load it efficiently, by loading it in chunks. You can also write code to aggregate/summarise data, or sample it.

cs95
  • 379,657
  • 97
  • 704
  • 746
1

I think you need first create DataFrame obviously by read_csv and then DataFrame.plot:

pd.read_csv('path_to_data').plot()

But if need plot DataFrames created from paths from column in DataFrame:

df.path_to_data.apply(lambda x: pd.read_csv(x).plot())

Or use custom function:

def f(x):
    pd.read_csv(x).plot()

df.path_to_data.apply(f)

Or use loop:

for x in df.path_to_data:
    pd.read_csv(x).plot()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252