我有一个像这样的 pandas 数据框:
d = {'col1': ['hi there', 'what are you doing', 'cool'], 'col2': [3, 4, 5]}
df = pd.DataFrame(data=d)
我使用数据框将命令行参数逐行传递给函数。
我的问题是有空格,所以我需要转义它们才能正确地将整行作为参数传递
我努力了
df.replace(" ", "\ ").head()
但这似乎并没有起到任何作用。替换数据框中的所有空格以获得下面的输出的最佳方法是什么?
输出:
d = {'col1': ['hi\ there', 'what\ are\ you\ doing', 'cool'], 'col2': [3, 4, 5]}
df = pd.DataFrame(data=d)
翻过高山走不出你
叮当猫咪
相关分类