ParserError: 数据标记化错误。C错误:在第27行期望1个字段,但看到367个。

huangapple go评论64阅读模式
英文:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 27, saw 367

问题

plz...我累了,帮我搞清楚

这是我的代码

import pandas as pd
url="https://github.com/selva86/datasets/blob/master/Ionosphere.csv"
df=pd.read_csv(url)
df.head()

ParserError: 数据标记错误。C错误:在第27行期望1个字段,看到367。

英文:

plz...I'm tired, help me to figure out

This is my code

import pandas as pd
url="https://github.com/selva86/datasets/blob/master/Ionosphere.csv"
df=pd.read_csv(url)
df.head()

ParserError: Error tokenizing data. C error: Expected 1 fields in line 27, saw 367

答案1

得分: 1

你需要转换你的URL,以包含raw.githubusercontent.com域。raw.githubusercontent.com域用于提供存储在GitHub存储库中的文件的未经处理版本。如果你在GitHub上浏览文件,然后点击Raw链接,你将进入那里。这是你的代码中会是什么样子:

import pandas as pd
url="https://raw.githubusercontent.com/selva86/datasets/master/Ionosphere.csv"
df=pd.read_csv(url)

df.head()返回:

       V1  V2       V3       V4       V5       V6       V7       V8       V9      V10      V11      V12  ...      V24      V25      V26      V27      V28      V29      V30      V31      V32      V33      V34  Class
0   1   0  0.99539 -0.05889  0.85243  0.02306  0.83398 -0.37708  1.00000  0.03760  0.85243 -0.17755  ... -0.47357  0.56811 -0.51171  0.41078 -0.46168  0.21266 -0.34090  0.42267 -0.54487  0.18641 -0.45300      1
1   1   0  1.00000 -0.18829  0.93035 -0.36156 -0.10868 -0.93597  1.00000 -0.04549  0.50874 -0.67743  ... -0.35734 -0.20332 -0.26569 -0.20468 -0.18401 -0.19040 -0.11593 -0.16626 -0.06288 -0.13738 -0.02447      0
2   1   0  1.00000 -0.03365  1.00000  0.00485  1.00000 -0.12062  0.88965  0.01198  0.73082  0.05346  ... -0.12062  0.57528 -0.40220  0.58984 -0.22145  0.43100 -0.17365  0.60436 -0.24180  0.56045 -0.38238      1
3   1   0  1.00000 -0.45161  1.00000  1.00000  0.71216 -1.00000  0.00000  0.00000  0.00000  0.00000  ...  0.00000  1.00000  0.90695  0.51613  1.00000  1.00000 -0.20099  0.25682  1.00000 -0.32382  1.00000      0
4   1   0  1.00000 -0.02401  0.94140  0.06531  0.92106 -0.23255  0.77152 -0.16399  0.52798 -0.20275  ... -0.52879  0.03286 -0.65158  0.13290 -0.53206  0.02431 -0.62197 -0.05707 -0.59573 -0.04608 -0.65697      1
英文:

You need to convert your URL so that it contains the raw.githubusercontent.com domain. The raw.githubusercontent.com domain is used to serve unprocessed versions of files stored in GitHub repositories. If you browse to a file on GitHub and then click the Raw link, that's where you'll go. This is what it would look like in your code:

import pandas as pd
url="https://raw.githubusercontent.com/selva86/datasets/master/Ionosphere.csv"
df=pd.read_csv(url)

df.head() returns:

   V1  V2       V3       V4       V5       V6       V7       V8       V9      V10      V11      V12  ...      V24      V25      V26      V27      V28      V29      V30      V31      V32      V33      V34  Class
0   1   0  0.99539 -0.05889  0.85243  0.02306  0.83398 -0.37708  1.00000  0.03760  0.85243 -0.17755  ... -0.47357  0.56811 -0.51171  0.41078 -0.46168  0.21266 -0.34090  0.42267 -0.54487  0.18641 -0.45300      1
1   1   0  1.00000 -0.18829  0.93035 -0.36156 -0.10868 -0.93597  1.00000 -0.04549  0.50874 -0.67743  ... -0.35734 -0.20332 -0.26569 -0.20468 -0.18401 -0.19040 -0.11593 -0.16626 -0.06288 -0.13738 -0.02447      0
2   1   0  1.00000 -0.03365  1.00000  0.00485  1.00000 -0.12062  0.88965  0.01198  0.73082  0.05346  ... -0.12062  0.57528 -0.40220  0.58984 -0.22145  0.43100 -0.17365  0.60436 -0.24180  0.56045 -0.38238      1
3   1   0  1.00000 -0.45161  1.00000  1.00000  0.71216 -1.00000  0.00000  0.00000  0.00000  0.00000  ...  0.00000  1.00000  0.90695  0.51613  1.00000  1.00000 -0.20099  0.25682  1.00000 -0.32382  1.00000      0
4   1   0  1.00000 -0.02401  0.94140  0.06531  0.92106 -0.23255  0.77152 -0.16399  0.52798 -0.20275  ... -0.52879  0.03286 -0.65158  0.13290 -0.53206  0.02431 -0.62197 -0.05707 -0.59573 -0.04608 -0.65697      1

[5 rows x 35 columns]

huangapple
  • 本文由 发表于 2023年4月4日 10:13:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定