我有一个列名 col1 和 col2 的整数类型条目的数据框。我想将 col1 的条目与 col2 以及中间的“.”(点)连接起来。我搜索并发现要添加两个列条目:
df['col'] = df['col1'].map(str) + df['col2'].map(str)
Run Code Online (Sandbox Code Playgroud)
并添加一个点:
df['col'] = df['col1'].astype(str) + '.'
Run Code Online (Sandbox Code Playgroud)
但我想要这样的东西
df['col'] = each entries of df['col1'] + '.' + each entries of df['col2']
Run Code Online (Sandbox Code Playgroud)
.map(str) 和 .astype(str) 之间有什么区别。这适合我的情况。