パンダについてValueError:最初は数値以外のデータエラーではサポートされていません



About Pandas Valueerror



import numpy as np from pandas import DataFrame, Series import pandas as pd s1 = pd.Series(list('86604 ')) s1 Out[7]: 0 8 1 6 2 6 3 0 4 4 5 dtype: object # Sort s1 with method='first' rank s1.rank(method='first')

エラーの内容は次のとおりです。

画像

解決:

''' Analysis: The reason for the error is that the type of s1 is incorrect. The data type obtained by pd.Series(list('86604')) is object, and list cannot sort non-numeric data Solution: 1. Convert the data type to numeric type through the to_numeric function: pd.to_numeric(s1, errors='coerce') [to_numeric official document](https://pandas.pydata.org/pandas-docs/version/0.20/generated/pandas.to_numeric.html) 2. Use list comprehension to create data: pd.Series([np.nan if e == '' else int(e) for e in list('86604 ')]) '''

画像