'Plot data from a csv file in a spesific intervall

I am trying to plot data from a csv-file where the y-axis represents resistance and the x-axis time. But I dont want to plot all of the data, only the data that start at 2022-02-21 10:44:00 and end at 2022-02-21 10:54:00 Here's a sample of the data:

    timestamp               resistance
2022-02-21 10:44:35.792893  10460.5248
2022-02-21 10:44:35.822877  10460.5048
2022-02-21 10:44:35.842826  10460.48
2022-02-21 10:44:35.872597  10460.4776
2022-02-21 10:44:35.892827  10460.4512
2022-02-21 10:44:35.922595  10460.4288

Here is the code and i think it will work but i keep getting (ValueError: time data = doesn't match format specified), and i dont know how to fix it. I think that the timestamp is in string since it when i try to plot the data the plot gets messed up. so i think that i need to convert the timestamp data to maybe datetime first.

from sqlite3 import Timestamp
import pandas as pd
import matplotlib.pyplot as plt
import csv
import numpy as np
from datetime import datetime

dt_format='%Y-%m-%d %H:%M:%S.%f'


data=pd.read_csv('data_keithley1.csv')
start = '2022-02-21 10:45:00.462227'
end = '2022-02-21 10:56:00.004844'

data['timestamp'] =  pd.to_datetime(data['timestamp'], format=dt_format)
timestamps = list(data['timestamp'])
values = list(data['resistance'])


start_index = timestamps.index(start)
end_index = timestamps.index(end)

sub_timestamps = timestamps[start_index : end_index]
sub_values = values[start_index : end_index]

plt.plot(sub_timestamps, sub_values, label='Motstand [ohm]')
plt.xlabel('time [hh:mm:ss]')
plt.ylabel('Mot [ohm]')
plt.subplots_adjust(bottom=0.35)
_, labels = plt.xticks()
plt.setp(labels, rotation=45)
plt.show()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source