FileNotFoundError: [Errno 2] File ../OUTPUT/spotify.csv does not exist: '../OUTPUT/spotify.csv'

Whenever I try to execute a few functions I get this massive error.

File "/home/laura/.local/lib/python3.8/site-packages/streamlit/ScriptRunner.py", line 319, in _run_script
    exec(code, module.__dict__)
File "/home/laura/Desktop/Music/all.py", line 87, in <module>
    b=st.write(classify_playlist(p))
File "/home/laura/.local/lib/python3.8/site-packages/streamlit/caching.py", line 591, in wrapped_func
    return get_or_create_cached_value()
File "/home/laura/.local/lib/python3.8/site-packages/streamlit/caching.py", line 575, in get_or_create_cached_value
    return_value = func(*args, **kwargs)
File "/home/laura/Desktop/Music/all.py", line 65, in classify_playlist
    spotify=pd.read_csv('../OUTPUT/spotify.csv')
File "/home/laura/.local/lib/python3.8/site-packages/pandas/io/parsers.py", line 676, in parser_f
    return _read(filepath_or_buffer, kwds)
File "/home/laura/.local/lib/python3.8/site-packages/pandas/io/parsers.py", line 448, in _read
    parser = TextFileReader(fp_or_buf, **kwds)
File "/home/laura/.local/lib/python3.8/site-packages/pandas/io/parsers.py", line 880, in __init__
    self._make_engine(self.engine)
File "/home/laura/.local/lib/python3.8/site-packages/pandas/io/parsers.py", line 1114, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
File "/home/laura/.local/lib/python3.8/site-packages/pandas/io/parsers.py", line 1891, in __init__
    self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 374, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 674, in pandas._libs.parsers.TextReader._setup_parser_source

Hi @Laura -

Can you provide a bit more information? What code are you running, what repo did it come from, etc.?

Best,
Randy

Sure,this is my code and it is not working properly.I would like to get just the last function,as a result in my app but if it is not possible i would like it as it is.

import streamlit as st
import pandas as pd
import numpy as np
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import json
import os
from dotenv import load_dotenv
load_dotenv()
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier


cid = os.getenv("CLIENT_ID")
secret = os.getenv("CLIENT_SECRET")
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

st.title('Music recommendation system')
st.sidebar.title('Music recommendation system')
st.markdown('Tired of listening to the same music all the time? We discover you new songs!'"Try it now!!")
st.sidebar.markdown('Tired of listening to the same music all the time? We discover you new songs!'"Try it now!!")

sentence = st.text_input('Your playlist Id here:')



@st.cache(persist = True)
def analyze_playlist(*args):
    
    
    playlist_features_list = ["artist","track_name","track_id","danceability","energy","key","loudness","mode", "speechiness",'acousticness',"instrumentalness","liveness","valence","tempo", "duration_ms"]
    
    playlist_df = pd.DataFrame(columns = playlist_features_list)
    
   
    
    playlist_tracks = sp.playlist_tracks(*args)["items"]
    for track in playlist_tracks:
        
        playlist_features = {}
        
        playlist_features["artist"] = track["track"]["artists"][0]["name"]
        playlist_features["track_name"] = track["track"]["name"]
        playlist_features["track_id"] = track["track"]["id"]
        
    
        audio_features = sp.audio_features(playlist_features["track_id"])[0]
        for feature in playlist_features_list[3:]:
            playlist_features[feature] = audio_features[feature]
        
        
        track_df = pd.DataFrame(playlist_features, index = [0])
        playlist_df = pd.concat([playlist_df, track_df], ignore_index = True)
        
    return playlist_df
    
if sentence:
    st.write(analyze_playlist(sentence))
@st.cache
def load_data(nrows):
    spotify=pd.read_csv('../OUTPUT/spotify.csv')
    spotify.drop(columns=['Unnamed: 0'],inplace=True)
    return spotify


    

@st.cache(persist = True)
def classify_playlist(*args):
    spotify=pd.read_csv('../OUTPUT/spotify.csv')
    spotify.drop(columns=['Unnamed: 0'],inplace=True)
    
    y = spotify['intervals'].values
    X = spotify[['danceability', 'energy',
            'loudness',  'speechiness', 'acousticness',
           'instrumentalness', 'liveness', 'valence']].values
    X_train, X_test, y_train,y_test = train_test_split(X,y, test_size=0.2)


    forest = RandomForestClassifier(n_estimators=200)
    forest.fit(X_train, y_train)
    tx=p[['danceability', 'energy',
            'loudness',  'speechiness', 'acousticness',
           'instrumentalness', 'liveness', 'valence']].values
    testdata= forest.predict(tx)
    return testdata

p=st.write(analyze_playlist(sentence))


b=st.write(classify_playlist(p))
@st.cache(persist = True)
def recommend(*args):
    spotify=pd.read_csv('../OUTPUT/spotify.csv')
    spotify.drop(columns=['Unnamed: 0'],inplace=True)
    a=spotify.set_index('intervals')
    return a['track_name'].sample(n=50, random_state=1).tolist()

recommend(b)

In this code, you aren’t writing '../OUTPUT/spotify.csv' anywhere, are you? If not, then this file just exists somewhere?

I would guess that your working directory isn’t what you think it is, so '../OUTPUT/spotify.csv' doesn’t correctly refer to the file. I would first hardcode the exact file path into your code to ensure your code works, then figure out how to refer to that file directory in a more programmatic way.