简体   繁体   English

如何使用python中的pandas从csv文件读取?

[英]How do I read from a csv file using pandas in python?

I'm trying to read data from a csv file in python using pandas, but I keep getting a file not found error message. 我正在尝试使用pandas从python中的csv文件中读取数据,但是我不断收到未找到文件的错误消息。

import numpy as np
import pandas as pd
from datetime import datetime
import csv
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

#import experimental data
headers = ['wave', 'otti', 'sc', 'trans','wave_sol', 'sol_15am']
df = pd.read_csv('/Documents/Research/expdata.csv', names=headers, 
skiprows=[0])

Lets assume that Pandas cannot find the file as that is the error returned by Pandas. 假设熊猫无法找到文件,因为那是熊猫返回的错误。

Linux: Linux:

I see in your path, you have /Documents/Research/expdata.csv on a Linux/Unix system your "Documents" folder is likely located in /home/<<username>>/Documents . 我在您的路径中看到,您在Linux / Unix系统上具有/Documents/Research/expdata.csv ,您的“ Documents”文件夹可能位于/home/<<username>>/Documents Linux systems will be case sensitive when it comes to file paths. 对于文件路径,Linux系统将区分大小写。 So, /home/zerodf/Documents is NOT equivalent to /home/zerodf/documents . 因此, /home/zerodf/Documents 等同于/home/zerodf/documents

Mac OS: 苹果系统:

On Mac OS, I believe that would be /Users/<<username>>/Documents . 在Mac OS上,我相信应该是/Users/<<username>>/Documents Mac OS is case insensitive, but preserving . Mac OS 不区分大小写,但保留

Windows: 视窗:

On Windows, that will be C:\\users\\<<username>>\\Documents . 在Windows上,该目录为C:\\users\\<<username>>\\Documents Windows systems will not be case sensitive. Windows系统将不区分大小写。 On Windows, C:\\zerodf\\documents is equivalent to C:\\zerodf\\Documents . 在Windows上, C:\\zerodf\\documents等效于C:\\zerodf\\Documents

Python is going to take path's very literally. 从字面上看,Python会走的路。 However, when it comes to interactive data science, ipython will help you with path autocompetion. 但是,在交互式数据科学方面, ipython将帮助您进行路径自动完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM