What’s up everyone, welcome to my blog. Today I am going to share my progress in learning Python. I will call this series My Phyton Journey. In this first article, I am going to read a CSV file from Phyton. I am using Visual Studio Code to write this code entirely. I am not a Phyton guru or expert, I just want to write everything I learned here in this blog.
Install Pandas on Visual Studio Code
In the VSC Terminal, first, check the Python version just to make sure.
py -3 --version
Output:
Python 3.11.5
And then install Pandas with this command
py -m pip install pandas
Now restart Visual Studio Code and we are good to go.
Read CSV file using Python
My test.csv file is located under O:\Dhani\Retool Development\Scripts\ folder. So I use the following code. I use ‘r’ because I use the raw string of the file path. It is convenient and easier to use rather than using the double backslash.
import pandas
file_path = r'O:\Dhani\Retool Development\Scripts\test.csv'
df = pandas.read_csv(file_path)
print(df)
If I don’t use the r option, I get this error. So, using the r option is the quick solution.
No such file or directory: 'O:\\Dhani\\Retool Development\\Scripts\test.csv'
For more information about Phyton and Pandas, please follow the links below