我正在尝试开发一种过程,该过程会自动将strcmp()
Series
中的每个pandas
缩放到零。例如,如果我们使用以下df:
df
我正在手动调整每列,使其从零开始。您会注意到增量为+1或-1,但起始整数有所不同。
import pandas as pd
d = ({
'A' : [0,1,2,3],
'B' : [6,7,8,9],
'C' : [10,11,12,13],
'D' : [-4,-5,-4,-3],
})
df = pd.DataFrame(data=d)
输出:
df['B'] = df['B'] - 6
df['C'] = df['C'] - 10
df['D'] = df['D'] + 4
这不是非常有效,因为我必须遍历每个系列来确定比例因子。有没有更有效的方法来确定这一点?
答案 0 :(得分:2)
//creating new widget
Widget ratingSection = Container(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ ..............
],
),
);
//creating new var
var ratingSectionVar = Container(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ ..............
],
),
);
return MaterialApp( ......
....
body: ListView(
children: <Widget>[
ratingSection,
ratingSectionVar,
],
),
),
);
详细信息:
df = df.sub(df.iloc[0])
#same as
#df = df - df.iloc[0]
print (df)
A B C D
0 0 0 0 0
1 1 1 1 -1
2 2 2 2 0
3 3 3 3 1