# April sales data
df = pd.read_csv(r'C:\Users\joseph chang\OneDrive\Tax documents\Programming\Python\Pandas-Data-Science-Tasks-master\SalesAnalysis\Sales_Data\Sales_April_2019.csv')
# All sales data
files = [file for file in os.listdir(r'C:\Users\joseph chang\OneDrive\Tax documents\Programming\Python\Pandas-Data-Science-Tasks-master\SalesAnalysis\Sales_Data')]
#for file in files:
#print(file)
#df.head()
#empty df to sore all data
all_months_data = pd.DataFrame()
#concatenate the data into a single df
for file in files:
df = pd.read_csv(r'C:\Users\joseph chang\OneDrive\Tax documents\Programming\Python\Pandas-Data-Science-Tasks-master\SalesAnalysis\Sales_Data\'+file)
all_months_data = pd.concat([all_months_data, df])
all_months_data.head()
>Solution :
If you take a close look in an IDE (or stackoverflows code highlighter) you will notice that you have a string that isn’t ending. Python interpreter was expecting the a ‘ character to end the string, but instead found an EOL character representing the end of the file.
The reason your ‘ character wasn’t picked up was because a backslash is before it. the backslash is an escape character in python, meaning it has special qualities when read by the interpreter. To represent the backslash character, use TWO backslashes. I have adjusted your code below by changing your backslashes, it should work now.
# April sales data
df = pd.read_csv('C:\\Users\\joseph chang\\OneDrive\\Tax documents\\Programming\\Python\\Pandas-Data-Science-Tasks-master\\SalesAnalysis\\Sales_Data\\Sales_April_2019.csv')
# All sales data
files = [file for file in os.listdir('C:\\Users\\joseph chang\\OneDrive\\Tax documents\\Programming\\Python\\Pandas-Data-Science-Tasks-master\\SalesAnalysis\\Sales_Data')]
#for file in files:
#print(file)
#df.head()
#empty df to sore all data
all_months_data = pd.DataFrame()
#concatenate the data into a single df
for file in files:
df = pd.read_csv('C:\\Users\\joseph chang\\OneDrive\\Tax documents\\Programming\\Python\\Pandas-Data-Science-Tasks-master\\SalesAnalysis\\Sales_Data\\'+file)
all_months_data = pd.concat([all_months_data, df])
all_months_data.head()