TypeError: can not multiply sequence by non-int of type 'float' solution

These days when visual map drawn per capita consumption of always having problems, error is:
TypeError: CAN not Multiply by non-int Sequence of the type of 'float'
to see the literal meaning is well understood, that is, when it came to non-parsed integer floating point multiply operations can not lead, so wrong not because the data type, so the solution is to convert the data type!
So treasurer went to view an Excel spreadsheet data type data column.
Here Insert Picture Description
Open the Excel spreadsheet display say this column data in text format, so the direct select "Convert to number" this option!
Then this problem will be solved, and time to run the program again, find another new error ... see below:
Here Insert Picture Description
Here Insert Picture Description
Yes, it is still TypeError! Note to see the beginning of an error treasurer red painted line section (IS IF bins None) , this time treasurer suddenly think of it, this column there is a problem with missing values . Since when did crawling data, there is some value None coffee shop price, so was the treasurer of missing values were treated as "NaN". . .

Well, the problem is found, then the solution will have, first and then deal with missing values for data visualization. General handling of missing values There are several ways (next write), where the main filling method. But here if to fill with zeros missing values if not reasonable (coffee is how it will not have been free); mean filling stands to reason also, but part of a coffee shop here (in fact, those public comment on a comprehensive restaurant inside included coffee service are also enumerated a) there is the price too high, the average will be pulled up, it is not suitable ; and finally treasurer choose to use the adjacent value to fill in the missing value is relatively reasonable . Solve the code is as follows:

data['mean-price'].fillna(method='ffill') #这里选择的是相邻值填充的前面值ffill方法

Then successfully dealt with missing values, and per capita consumption are visualized.
Here Insert Picture Description

Published 30 original articles · won praise 29 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_41013322/article/details/104553935