【发布时间】:2019-01-23 16:01:02
【问题描述】:
我是处理熊猫 Df 的新手。 我想比较每一行的每一列元素。
要求: 如果 1 行的列中的所有元素都为零,则在新列中输入“More False”,并用与其索引对应的零填充。
请参阅下面的 Df 以获得清晰的理解
My Data Frame:
Time Brake Speed Strgangle index Target
0 1678.39 0.000000 0.000000 0.000000 167739 0
1 1678.40 15.00000 0.000000 0.000000 167740 0
2 1678.41 0.000000 8.000000 0.000000 167741 0
3 1678.42 0.000000 0.000000 2.000000 167742 0
4 1678.43 5.000000 20.10000 0.000000 167743 0
5 1678.44 0.150000 0.000000 -1.16500 167744 0
6 1678.45 0.000000 20.10 2.000000 167742 0
7 1678.47 0.150000 25.00000 -1.16500 167744 0
My Requirement :
1. If Brake = 0, Speed =0, Strg angle=0
--> Input a str in corresponding Target index as 'More False'
2. If Brake = Value, Speed = Value, Strg angle=Value
--> Input a str in corresponding Target index as 'More True'
3. As above conditions i should input the string in Target column based on my requirement
.
需要的实际 Df:
Time Brake Speed Strgangle index Target
0 1678.39 0.000000 0.000000 0.000000 167739 MoreFalse
1 1678.40 15.00000 0.000000 0.000000 167740 False
2 1678.41 0.000000 8.000000 0.000000 167741 False
3 1678.42 0.000000 0.000000 2.000000 167742 False
4 1678.43 5.000000 20.10000 0.000000 167743 True
5 1678.44 0.150000 0.000000 -1.16500 167744 True
6 1678.45 0.000000 20.10 2.000000 167742 True
7 1678.47 0.150000 25.00000 -1.16500 167744 MoreTrue
我尝试使用 If 循环在 Target 列中输入我需要的字符串,但我收到 SettingWithcopy 警告。
我相信对于上述问题会有一些简单的方法。
【问题讨论】:
-
查看 np.select
-
我的要求/条件 :(@FilipeAleixo) 1. 如果 Brake = 0, Speed =0, Strg angle=0 --> 在对应的 Target index 中输入 str 为 'More False' 2. 如果Brake = Value, Speed = Value, Strg angle=Value --> 在相应的目标索引中输入一个 str 为'More True' 3. 如上所述,我应该根据我的要求在目标列中输入字符串
标签: python python-3.x pandas dataframe warnings