Having difficulty opening a csv file in pandas, I have tried:
data = pd.read_csv("/home/me/Programming/data/sample.csv")
That did not work, so I tried:
import os
cwd = os.getcwd()
data = pd.read_csv(cwd + "sample.csv")
and that doesn't work either, just says that file does not exist, but it's there in the file manager clear as day.
os.getcwd()
return the current working directory without trailing path separtor.
You should use os.path.join
instead of +
to correctly join paths:
import os
cwd = os.getcwd()
data = pd.read_csv(os.path.join(cwd, 'sample.csv'))
BTW, there's no need to specify full path of current working directory; just specify sample.csv
should be enough:
data = pd.read_csv("sample.csv")
Make sure the file sample.csv
is in the current working directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With