trendet icon indicating copy to clipboard operation
trendet copied to clipboard

Trying to apply example on my own data

Open thebadguyfromstarwars opened this issue 3 years ago • 2 comments

As you can see above - the bold code is of my own making. I'm taking a column, predicted_stock_data[:,0], from a dataframe to use a the closing price. I then add the 'Date'. I can't grasp the problem with 'Date'.

res = predicted_stock_data[:,0] des = pd.DataFrame(res, columns = ['Close']) start = datetime(2018, 9, 29) dates = pd.date_range(start, periods=100).to_pydatetime().tolist() des['Dates'] = dates res = trendet.identify_df_trends(df=des, column='Close')

with plt.style.context('classic'): plt.figure(figsize=(20, 10)) ax = sns.lineplot(x=res['Date'], y=res['Close'])

labels = res['Up Trend'].dropna().unique().tolist()

for label in labels:
    sns.lineplot(x=res[res['Up Trend'] == label]['Date'],
                 y=res[res['Up Trend'] == label]['Close'],
                 color='green')

    ax.axvspan(res[res['Up Trend'] == label]['Date'].iloc[0],
               res[res['Up Trend'] == label]['Date'].iloc[-1],
               alpha=0.2,
               color='green')

labels = res['Down Trend'].dropna().unique().tolist()

for label in labels:
    sns.lineplot(x=res[res['Down Trend'] == label]['Date'],
                 y=res[res['Down Trend'] == label]['Close'],
                 color='red')

    ax.axvspan(res[res['Down Trend'] == label]['Date'].iloc[0],
               res[res['Down Trend'] == label]['Date'].iloc[-1],
               alpha=0.2,
               color='red')

plt.show()

err

thebadguyfromstarwars avatar Apr 28 '21 20:04 thebadguyfromstarwars

err2

Having this peculiar issue now.. hmm..

thebadguyfromstarwars avatar Apr 28 '21 21:04 thebadguyfromstarwars

use this DataFrame format image

Date is the index, and its type shoud be date not str

kdfrmy avatar Sep 03 '21 07:09 kdfrmy