1
有什麼方法可以統計熊貓數據幀中每列的值變化次數嗎?計算熊貓數據幀中每列值的變化
我不希望有自己的循環在每個塔,例如:
import pandas as pd
frame = pd.DataFrame({
'time':[1234567000,1234567005,1234567009],
'X1':[96.32,96.01,96.05],
'X2':[23.88,23.96,23.96]
},columns=['time','X1','X2'])
print(frame)
changes = []
for column_name in frame.columns.values:
print('column_name: {0}'.format(column_name))
changes.append(sum(frame[column_name]!=frame[column_name].shift(1)))
print('changes: {0}'.format(changes))
回報:
time X1 X2
0 1234567000 96.32 23.88
1 1234567005 96.01 23.96
2 1234567009 96.05 23.96
column_name: time
column_name: X1
column_name: X2
changes: [3, 3, 2]
謝謝!後續工作:[計算忽略NaN的熊貓數據框中每個列中值的變化](https://stackoverflow.com/q/45038037/395857) –