ValueError: cannot convert float NaN to integer

AI빅데이터|2020. 3. 14. 15:43
반응형

Python pandas의 dropna() method를 사용해서

 

 - 결측값이 들어있는 행 전체 제거

   (delete row with missing values)

 - 결측값이 들어있는 열 전체를 제거

   (delete column with missing values)

 - 특정 행 또는 열 만을 대상으로 결측값이 들어있으면 제거

   (delete specific row or column with missing values)



출처: https://rfriend.tistory.com/263 [R, Python 분석과 프로그래밍의 친구 (by R Friend)]

 

Sample codes>

con = sqlite3.connect(self.databasePath)
sqlCode = "SELECT * From '%s'" % self.stock_code
chart_data = pd.read_sql(sqlCode, con, index_col=None)
chart_data = chart_data.reset_index(drop=True)
#print('chart_data after reset_indexing: ')
close = chart_data['close']
moving_mean = close.rolling(120).mean() # 120() 이동평균을 구한다.
moving_mean = moving_mean.dropna(axis=0)
moving_std = close.rolling(120).std() # 120() 이동표준편차를 구한다.
moving_std = moving_std.dropna(axis=0)

moving_mean02 = moving_mean.iloc[-1:]
print('moving_mean02: ')
print(moving_mean02)
moving_mean02 = int(pd.DataFrame(moving_mean02).values)
moving_std02 = moving_std.iloc[-1:]
moving_std02 = int(pd.DataFrame(moving_std02).values)
moving_std02 = moving_std02 * 3

반응형

댓글()