我有一个数据帧df1,其中多个列包含相同的字符串子集。如何单独对这些列进行更改。例如,删除最后三个字符,更改列的数据类型,等等。我只是想更轻松地对具有相同字符子集的列进行更改(例如“Session”,如下所示)
第一个例子:
df1:
Session1 Session2 Session3 Total
3.0 4.0 5.0 5.0
2.0 1.0 4.0 NaN
df2 (Intended Output):
Session1 Session2 Session3 Total
3 4 5 5.0
2 1 4 Nan
第二个例子:
df1:
Session1 Session2 Session3 Total
3 4 5 5.0
2 1 4 Nan
df2 (Intended Out):
Sessi Sessi Sessi Total
3 4 5 5.0
2 1 4 NaN
关于你的第一点:
第二点:
第一步是过滤所有需要的目标列。你可以用
然后可以对这些列应用任何操作。例如,要更改数据类型,可以执行以下操作
编辑: 对于重命名和删除最后三个字符的第二点,您可以使用如下重命名函数:
相关问题 更多 >
编程相关推荐