程式碼:
a = 1
lsta = list(a)
print(lsta,type(lsta),len(lsta))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 3, in <module>
lsta = list(a)
TypeError: ‘int’ object is not iterable
int無法取list()
如果取array()呢?
程式碼:
import numpy as np
a = 1
arya = np.array(a)
print(arya, type(arya), len(arya))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 7, in <module>
print(arya,type(arya),len(arya))
TypeError: len() of unsized object
int可以取array(),
只是長度0 (不要誤會長度1)
所以取len()時錯誤
empty list: []長度也是0
去掉len()

3(1+2)的左右邊沒有[ ] 包覆
type為ndarray (0-dimensional)
用法同int
numpy官網:

2D array的運算:

推薦hahow線上學習python: https://igrape.net/30afN


![Python: pandas.DataFrame如何移除所有空白列?if df_raw.iloc[r,0] is np.nan: nanLst.append(r) ; df_drop0 = df_raw.drop(nanLst,axis=0) ; pandas.isna() ;df_drop0 = df_raw.drop(nanLst,axis=0).reset_index(drop=True) Python: pandas.DataFrame如何移除所有空白列?if df_raw.iloc[r,0] is np.nan: nanLst.append(r) ; df_drop0 = df_raw.drop(nanLst,axis=0) ; pandas.isna() ;df_drop0 = df_raw.drop(nanLst,axis=0).reset_index(drop=True)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/12/20221206144233_67.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







近期留言