实习中python编辑报错总结

实习中python编辑报错总结

2019.8.5 数据合并,清洗

1. pandas groupby 报错:Expected str instance, Float found

最后发现:其实是我的输入有问题
网上查到一种解决办法
You may have NaN in columns everything, adding fillna before groupby .
https://stackoverflow.com/questions/51977408/pandas-group-by-expected-str-instance-float-found

2. 如何去除列表中空字符串

filter(None, your_list) #速度更快
while '' in your_list:
    your_list.remove('')

3.遇到长得像list 的str 要变成list

如看起来是[‘7000.0’,‘8000.0’],实际上是’[’,‘7’,‘0’…

def Str2float(list1):
	list2=[]
	for i in list1:
		i = float(i.replace("'",""))
		list2.append(i)
	return list2
list1 = STR(1:len(STR)-1)
list1 = Str2float(list1)

你可能感兴趣的:(实习中python编辑报错总结)