'Why does it say 'Series' object is not callable when I think that I did everything right
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('fivethirtyeight')
data = pd.read_csv("TSLA.csv")
data = data.set_index(pd.DatetimeIndex(data["Date"].values))
plt.figure(figsize=(12.2, 4.5))
plt.title('Close Price', fontsize = 18)
plt.plot(data['Close'])
plt.xlabel(["Date"], fontsize = 18)
plt.ylabel(["Close"], fontsize = 18)
I just wanted to have a nice graph of this data but I got the error on the line ---> plt.plot(data['Close'])
Solution 1:[1]
I tried out your code for myself, and it worked. The error that you probably had, occurs if the column Close does not exist in the dataframe / csv file.
Could you check if there is a space after the separators (e.g. , or ;) in your file?
Removing them should provide you with the correct results.
On a side note, you can also use the plotting functionality of pandas to plot a dataframe. In your example, this could be like:
ax = data.plot(y="Close", kind="line", fontsize=18, figsize=(12.2, 4.5))
ax.set_title("Close Price", fontdict={"fontsize":18})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
