[Python] Open the csv file in the folder specified by pandas

I came up with the idea of analyzing data in Python 2.7.6 with pycharm. Unable to read the csv file to be analyzed, After investigating various things for several hours, I solved it by the following method.

What I didn't do first (read csv directly with read_csv)

Well, it seems that pandas is good for analyzing data, So I installed pandas on pycharm. So, it seems that you can read csv by using read_csv of pandas, so I immediately tried the following.

Csv reading using pandas


import pandas as pd

df = pd.csv_read("/File path to directory/test.csv")
print df

However, as a result, it cannot be read and the following error message is displayed. .. ..

csv read result in pandas


IOError: File test.csv does not exist

Solved this way (change working directory)

After a lot of research to solve this problem, Apparently the csv_read method is directly from the file path I can't call the file, and even where the file I want to call is I found that I had to specify the path and change the working directory.

I had to use os.chdir to change the working directory.

Specify a working directory and read csv using pandas


import pandas as pd
import os

#Specify the path to the working directory where the data is stored
os.chdir("/File path to directory")
#read csv
df= pd.read_csv("test.csv")
print df

With the above method, I was able to read csv safely!

Recommended Posts

[Python] Open the csv file in the folder specified by pandas
Read the file line by line in Python
Read the file line by line in Python
[Python] Read the specified line in the file
A memo organized by renaming the file names in the folder with python
Download the file in Python
I tried to open the latest data of the Excel file managed by date in the folder with Python
File / folder path manipulation in Python
Save the binary file in Python
Sort the file names obtained by Python glob in numerical order
Read all csv files in the folder
Pandas of the beginner, by the beginner, for the beginner [Python]
Csv in python
Test & Debug Tips: Create a file of the specified size in Python
Open an Excel file in Python and color the map of Japan
[Python] Get the files in a folder with Python
[Python] Sort the table by sort_values (pandas DataFrame)
Transpose CSV file in Python Part 2: Performance measurement
How to get the files in the [Python] folder
Download the csv file created by Google Colaboratory
Speed evaluation of CSV file output in Python
Various ways to read the last line of a csv file in Python
How to read all the classes contained in * .py in the directory specified by Python
Divides the character string by the specified number of characters. In Ruby and Python.
Get Unix time of the time specified by JST regardless of the time zone of the server in Python
[Python] Scan the inside of the folder including subfolders → Export the file list to CSV
I tried searching for files under the folder with Python by file name
File processing in Python
Read CSV file: pandas
File operations in Python
Read Python csv file
Download the file while viewing the progress in Python 3.x
Get the file name in a folder using glob
Collectively register data in Firestore using csv file in Python
I tried to touch the CSV file with Python
Read the csv file and display it in the browser
The story of FileNotFound in Python open () mode ='w'
Read the xml file by referring to the Python tutorial
How to convert JSON file to CSV file with Python Pandas
Shift the alphabet string by N characters in Python
Let's use the open data of "Mamebus" in Python
Store the stock price scraped by Python in the DB
Output the specified table of Oracle database in Python to Excel for each file
Read csv with python pandas
How to switch the configuration file to be read by Python
Find the difference in Python
Change the standard output destination to a file in Python
[Python] Read the csv file and display the figure with matplotlib
Python> library> os> os.walk ()> Get directory structure / Implementation to get each file path in the specified directory
Get the MIME type in Python and determine the file format
Python command in "Social network analysis learned by open source"
[Note] Import of a file in the parent directory in Python
Batch convert all xlsx files in the folder to CSV files
After enabling the python virtual environment in the batch file, run the python file
Solve the Japanese problem when using the CSV module in Python.
Visualize the correlation matrix by principal component analysis in Python
Google search for the last line of the file in Python
Download csv file with python
Sort by date in python
The Power of Pandas: Python
If I thought I didn't see the pyc file recently, it was quarantined in pycache by python3.