ChanChunky
ChanChunky

Reputation: 1

How to plot data over time

I have some calcium imaging data (measuring the intensity of a fluorescence molecule that responds to cellular calcium levels) in Excel that I can use for practicing Python. I imported the data into Python as csv, then tried to plot calcium concentration versus time. The trouble I have is, Python expect time to be expressed as Year-Month-Day-Hour-Minute-Second. But I only have Hour-Minute-Second. So want to ask, is Python always expecting time as Year-Month-Day-Hour-Minute-Second and therefore I just need to make up a day, or, can I use some command to tell Python to only use Day-Hour-Minute?

Upvotes: 0

Views: 255

Answers (1)

Batman
Batman

Reputation: 8927

Python doesn't expect anything, except that you give it a date. Or something date like. (To be perfectly fair, Python doesn't even expect that. You just need to give Python something date like if you want to to behave the way you expect.).

Probably the easiest way is to read the csv into a Dataframe, and then use plot. Once you've got that down, you can start looking at using Matplotlib, or Seaborn, etc.

So, assuming that when you say "I only have hour-minute-second" what you mean is that the date was the same for each point, you could do something like this.

import datetime

import pandas as pd

date = "20170707 "
times = ["09-00-00", "10-00-00", "11-00-00"]
timestamps = [datetime.datetime.strptime(date + time, "%Y%m%d %H-%M-%S") for time in times]
df = pd.DataFrame(data={"Ca": [2, 1, 3]}, index=timestamps)
df.plot()

Upvotes: 1

Related Questions