데이터 프레임의 대체 방법은 열 유형을 객체에서 부동으로 변경하는 것입니다. 객체 유형을 np.nan과 혼합하고 열을 Dtype "object"로 유지하는 방법이 있습니까?
df = df.replace("0", np.nan)
전에:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 109 entries, 12 to 120
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 transaction_date 81 non-null object
1 remark 81 non-null object
2 withdrawal 81 non-null object
3 deposit 81 non-null object
4 balance 81 non-null object
dtypes: object(5)
memory usage: 4.4+ KB
후:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 109 entries, 12 to 120
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 transaction_date 81 non-null object
1 remark 81 non-null object
2 withdrawal 52 non-null float64
3 deposit 29 non-null float64
4 balance 80 non-null float64
dtypes: float64(3), object(2)
memory usage: 4.4+ KB
다음으로 바꿀 수 있습니다 None
.
df = df.replace("0", None)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다