问题 I have a dataframe in pyspark which has 15 columns. The column name are id , name , emp.dno , emp.sal , state , emp.city , zip ..... Now I want to replace the column names which have '.' in them to '_' Like 'emp.dno' to 'emp_dno' I would like to do it dynamically How can I achieve that in pyspark? 回答1: You can use something similar to this great solution from @zero323: df.toDF(*(c.replace('.', '_') for c in df.columns)) alternatively: from pyspark.sql.functions import col replacements = {c:c