使用 pandas 遇到的报错

TypeError: parser_f() got multiple values for argument 'sep'

import pandas as pd


fund1 = pd.read_csv(r'fund_info1.csv','r',encoding='utf-8',sep=',')
print(fund1)

需要改成如下

import pandas as pd


fund1 = pd.read_csv(open(r'fund_info1.csv','r',encoding='utf-8'))
print(fund1)

 

 

os.stat(path)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 29: invalid continuation byte

此错误为打开文件路径包含了中文,需要加上 open() 函数打开

 

 

InternalError: (1050, "Table 'ch4ex9' already exists")

mysql 创建表,表已经存在

 

ParserError: Error tokenizing data. C error: Expected 1 fields in line 95, saw 2

使用 pd.read_csv() 打开出错,改用 pd.read_csv(open()) 来打开文件

 

AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas

错误:

data2['qiushi_age'] = data2['qiushi_age'].str.replace('天','')

正确:

data2['qiushi_age'] = data2['qiushi_age'].apply(str).replace('天','')

 

AttributeError: 'Series' object has no attribute 'strip'

用 replace

 

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

用值错误,比如需要选择满足2个条件的行,每个条件都需要用括号括起来,且不是 and 是 &

你可能感兴趣的:(报错)