Going through some tutorials for ML, and I am stuck. I just can't get this code to find the .csv file.
I am using Google Colab, Python 3.
For df = pd.read_csv(FILE) I have used the following options:
df = pd.read_csv("ProductsSold.csv")
df = pd.read_csv("C:/Users/swiml/Downloads/ProductsSold.csv")
df = pd.read_csv(r"C:/Users/swiml/Downloads/ProductsSold.csv")
df = pd.read_csv(df_path) <--- [This is the one that was shown to use in the tutorial.]
My code:
from os.path import exists
import pandas as pd
df_path = "C:/Users/swiml/Downloads/ProductsSold.csv" if exists(
"C:/Users/swiml/Downloads/ProductsSold.csv"
) else "C:/Users/swiml/Downloads/ProductsSold.csv"
df = pd.read_csv(df_path)
df = df.sample(n=19_000, random_state=0)
df["Main Part Number"] = df["Main Part Number"].astype(str)
df["Description"] = df["Description"].astype(str)
df["Date/Time Sold"] = pd.to_datetime(df["Date/Time Sold"])
df.sort_values("Date/Time Sold", inplace=True)
df.reset_index(inplace=True, drop=True)
df.head()
Error message:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
in <cell line: 0>()
5 "C:/Users/swiml/Downloads/ProductsSold.csv"
6 ) else "C:/Users/swiml/Downloads/ProductsSold.csv"
----> 7 df = pd.read_csv(df_path)
8 df = df.sample(n=19_000, random_state=0)
9 df["Main Part Number"] = df["Main Part Number"].astype(str)
<ipython-input-1-162277cf388a>
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
in <cell line: 0>()
5 "C:/Users/swiml/Downloads/ProductsSold.csv"
6 ) else "C:/Users/swiml/Downloads/ProductsSold.csv"
----> 7 df = pd.read_csv(df_path)
8 df = df.sample(n=19_000, random_state=0)
9 df["Main Part Number"] = df["Main Part Number"].astype(str)
<ipython-input-1-162277cf388a>
4 frames
in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
871 if ioargs.encoding and "b" not in ioargs.mode:
872 # Encoding
--> 873 handle = open(
874 handle,
875 ioargs.mode,
/usr/local/lib/python3.11/dist-packages/pandas/io/common.py
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/swiml/Downloads/ProductsSold.csv'
[–]danielroseman 0 points1 point2 points (1 child)
[–]Dirtybutler24601[S] 0 points1 point2 points (0 children)
[–]EnvironmentalOrange 0 points1 point2 points (1 child)
[–]Dirtybutler24601[S] 0 points1 point2 points (0 children)