如何在Google Colab中使用Pandas 'sep'命令?

How to use the Pandas 'sep' command in Google Colab?

所以,我使用了 Jupyter Notebook,使用 'sep' 命令非常简单。但现在我正在慢慢迁移到 Google Colab,虽然我可以找到文件并使用 'pd.read_csv()' 构建 DataFrame,但我似乎无法使用 'sep = ' 命令分隔列!

我安装了驱动器并找到了文件:

import pandas as pd
from google.colab import drive
drive.mount('/content/gdrive')
with open('/content/gdrive/My Drive/wordpress/cousins.csv','r') as f:
  f.read()

然后我构建了数据框:

df = pd.read_csv('/content/gdrive/My Drive/wordpress/cousins.csv',sep=";")

dataframe构建完成,但没有按列分隔!下面是截图:

Built DataFrame

最后编辑:原来问题出在我尝试使用的数据上,因为它在 Jupyter 上也不起作用。 'sep' 命令的使用方式没有问题!

PS: 我也尝试了 'sep='.'' 和 'sep = ','' 看看是否有效,但没有任何效果。

我从 Football-Reference 下载了 'csv' table 数据,粘贴到 excel,保存为 csv (UTF-8),文件示例可以在这里找到:

Pastebin Example File

这对我有用:

我的数据:

a,b,c
5,6,7
8,9,10

逗号分隔文件不需要 sep。

from google.colab import drive
drive.mount('/content/drive')

import pandas as pd

# suppose I have data in my Google Drive in the file path
# GoogleColaboratory/data/so/a.csv
# The folder GoogleColaboratory is in my Google Drive.
df = pd.read_csv('drive/My Drive/GoogleColaboratory/data/so/a.csv')
df.head()

而不是

df = pd.read_csv('/content/gdrive/My Drive/wordpress/cousins.csv', sep=";")

使用

df = pd.read_csv('/content/gdrive/My Drive/wordpress/cousins.csv', delimiter=";")