0

UPDATED CODE:

file_name2 =r'C:\Users\Trading\Desktop\scott\initialTrades.csv'
df=pd.read_excel(file_name2)

print (df)

This returns error XLRDError.

file_name2 =r'C:\Users\Trading\Desktop\scott\initialTrades.xlsx'
df=pd.read_excel(file_name2)

print (df)   

This returns error: FileNotFoundError.


file_name ='C:\Users\Trading\Desktop\scott' file_double="C:\Users\Trading\Desktop\scott"

I put two \ instead of \ as python replace single backslash with double backslash this article states to ger rid of the (unicode error) 'unicodeescape'

What small step am I missing?

Here is the rest of my code:

sheet =initialTrades #I also tried 'initialTrades'

df = pd.read_excel(io=file_double, sheet_name=sheet)
print(df.head(5))  # print first 5 rows of the dataframe
John Smith
  • 97
  • 8
  • 2
    did you read the *answer* on that link too? try with a simple `r` flag. `file_name =r'C:\Users\Trading\Desktop\scott'` – Paritosh Singh Jun 25 '19 at 17:43
  • I tried a various number of answers yes. Most of them vary in different ways which makes me unclear of which one is actually the 'right' answe – John Smith Jun 25 '19 at 17:45
  • For instance, `directory = str(r"C:\Users\Trading\Desktop\scott").replace('\\','\\\\') `still gets the same error. – John Smith Jun 25 '19 at 17:46
  • don't do all that. where did `directory` come from? Just, clear everything, start over, use a `r` before the fullpath. that's it. `file_name =r'C:\Users\Trading\Desktop\scott'` then you should get more useful errors or atleast focus on the more concerning things, such as the fact that the path you've given here is clearly not an excel file, it seems like just until the folder. – Paritosh Singh Jun 25 '19 at 17:49
  • `file_name2 =r'C:\Users\Trading\Desktop\scott' sheet =initialTrades df = pd.read_excel(io=file_name2, sheet_name=sheet) print(df.head(5)) # print first 5 rows of the dataframe` This code still gets the same error. So I am using an Excel file, but it is CSV (comma delim). That could be the issue... – John Smith Jun 25 '19 at 17:50
  • and? what happens? (also, what is `initialTrades`?) – Paritosh Singh Jun 25 '19 at 17:53
  • initialTrades is the Excel (CSV delim) file name. The code above gets the same error still. – John Smith Jun 25 '19 at 17:54
  • ack. just write `file_name2 =r'C:\Users\Trading\Desktop\scott\initialTrades.xlsx'` (im assuming .xlsx format, you never mentioned it. is it .csv instead??) . and then just `pd.read_excel(file_name2)`. – Paritosh Singh Jun 25 '19 at 17:56
  • Ok I agree with your code but got a FileNotFoundError. Yes it is an excel CSV file. I also tried .csv. and got a XLRDError – John Smith Jun 25 '19 at 18:00
  • can you edit the code you tried and the error into the question please? – Paritosh Singh Jun 25 '19 at 18:02
  • good idea. I just updated the code on very top. – John Smith Jun 25 '19 at 18:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195528/discussion-between-paritosh-singh-and-john-smith). – Paritosh Singh Jun 25 '19 at 18:07

0 Answers0