【error solved】Error tokenizing data. C error: Expected 1 fields in line XX, saw XX

报错内容:Error tokenizing data. C error: Expected 1 fields in line XX, saw XX
报错原因:CSV的分隔符设置异常 / 存储的时候格式有问题
解决方法:

方法一

通过csv库进行读取,再遍历,再进行合并保存 (文件不大的情况下可用),太大转置的时候RAM会hang

import pandas as pd
import csv 
path = 'file_absolute_path/filename.csv'
test = pd.DataFrame()
data = csv.reader(open(path, 'r'))
for d in data:
    # print(d)
    result = pd.DataFrame(d).T
    test = pd.concat([test,result])
test = test.reset_index(drop = True)

Ref:
https://blog.csdn.net/qq_33267306/article/details/120284044

方法二

跳过错误的行

df = pd.read_csv(filename, error_bad_lines = False)

The error_bad_lines argument has been deprecated and will be removed in a future version.

documentation

Deprecated since version 1.3.0: The on_bad_lines parameter should be used instead to specify behavior upon encountering a bad line instead.

So, replace with:

df = pd.read_csv(filepath, error_bad_lines = 'skip')
方法三
df = pd.read_csv(filepath, delimiter = '\t')
# or
df = pd.read_csv(filepath, sep = '\t')
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
The best-selling author of Big Data is back, this time with a unique and in-depth insight into how specific companies use big data. Big data is on the tip of everyone's tongue. Everyone understands its power and importance, but many fail to grasp the actionable steps and resources required to utilise it effectively. This book fills the knowledge gap by showing how major companies are using big data every day, from an up-close, on-the-ground perspective. From technology, media and retail, to sport teams, government agencies and financial institutions, learn the actual strategies and processes being used to learn about customers, improve manufacturing, spur innovation, improve safety and so much more. Organised for easy dip-in navigation, each chapter follows the same structure to give you the information you need quickly. For each company profiled, learn what data was used, what problem it solved and the processes put it place to make it practical, as well as the technical details, challenges and lessons learned from each unique scenario. Learn how predictive analytics helps Amazon, Target, John Deere and Apple understand their customers Discover how big data is behind the success of Walmart, LinkedIn, Microsoft and more Learn how big data is changing medicine, law enforcement, hospitality, fashion, science and banking Develop your own big data strategy by accessing additional reading materials at the end of each chapter Table of Contents Chapter 1 Walmart Chapter 2 CERN Chapter 3 Netflix Chapter 4 Rolls-Royce Chapter 5 Shell Chapter 6 Apixio Chapter 7 Lotus F1 Team Chapter 8 Pendleton & Son Butchers Chapter 9 US Olympic Womens Cycling Team Chapter 10 ZSL Chapter 11 Facebook Chapter 12 John Deere Chapter 13 Royal Bank of Scotland Chapter 14 LinkedIn Chapter 15 Microsoft Chapter 16 Acxiom Chapter 17 US Immigration And Customs Chapter 18 Nest Chapter 19 GE Chapter 20 Etsy Chapter 21 Narrative Science Chapter 22 BBC Chapter 23 Milton Keynes Chapter 24 Palantir Chapte

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值