Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据框选项卡和空白修剪_Python_Pandas_Jupyter Notebook - Fatal编程技术网

Python 数据框选项卡和空白修剪

Python 数据框选项卡和空白修剪,python,pandas,jupyter-notebook,Python,Pandas,Jupyter Notebook,我正在将.csv文件读入熊猫数据帧。我把文件读作: df = pd.read_csv(filepath, sep='\t') 文本标题看起来像(\s spaces\t tab) Date\s\s\tPlace\s\s\s\s\tLow\s\s\s\t\s\s\s\s\t 我正在使用'\t'sep将文件读入数据帧。但问题是,如果我尝试使用df['Date']访问其中一列,我会得到一个keyrerror:'Date'。我认为有空白,也许还有标签,熊猫在阅读专栏时不会去掉?如何从列标题中删除空格和制

我正在将.csv文件读入熊猫数据帧。我把文件读作:

df = pd.read_csv(filepath, sep='\t')
文本标题看起来像(\s spaces\t tab)

Date\s\s\tPlace\s\s\s\s\tLow\s\s\s\t\s\s\s\s\t


我正在使用'\t'sep将文件读入数据帧。但问题是,如果我尝试使用df['Date']访问其中一列,我会得到一个keyrerror:'Date'。我认为有空白,也许还有标签,熊猫在阅读专栏时不会去掉?如何从列标题中删除空格和制表符?

让我们使用
.str.strip

df.columns = df.columns.str.strip()

df=pd.read\u csv(filepath,delim\u whitespace=True)
?谢谢!成功了。