Hello, I have a .csv that has 2 columns. The first column contains timestamps and the second column CO2 measurements. What I want to do is to plot the data, but on x-axis instead of depicting timestamps I want to print strings, such as: "name_1" , "name_2", "name_3"... Any ideas?
Swapping what columns is x or y is easy.
import pandas as pd
import random
import matplotlib.pyplot as plt
times = pd.date_range(start='2022-03-1', end='2022-03-21', periods=21)
levels = [random.randint(1, 10) for _ in times]
df = pd.DataFrame({"date": times, "level": levels})
print(df)
df.plot(kind="line", x="date", y="level")
df.plot(kind="scatter", x="level", y="date")
plt.show()
I don't understand what you mean by this:
What I want to do is to plot the data, but on x-axis instead of depicting timestamps I want to print strings, such as: "name_1" , "name_2", "name_3".
What are these names? You said you hand two columns, only two things to plot; date and level. Where do these names come in?
But if you have a bunch of names, you can add them as a column to your dataframe and select the name column as one of the things that is plotted.
Then you need to create a column that contains "day 1", "day 2", etc... These can probably be created using pandas datetime tools.
import pandas as pd
import random
import matplotlib.pyplot as plt
times = pd.date_range(start='2022-03-1', end='2022-03-21', periods=21)
levels = [random.randint(1, 10) for _ in times]
df = pd.DataFrame({"date": times, "level": levels})
df["days"] = (df["date"] - times[0]).dt.days.astype('int16')
df.plot(kind="line", x="days", y="level")
print(df)
plt.show()