हिंदी

Which of the following Python statements is used to change a column label in a DataFrame, df? - Informatics Practices

Advertisements
Advertisements

प्रश्न

Which of the following Python statements is used to change a column label in a DataFrame, df?

विकल्प

  • df = df.rename({old_name : new_name}, axis=‘columns’)

  • df = df.rename(old_name, new_name),axis=‘columns’

  • df = df.change_name(old_name, new_name, axis=‘bar’)

  • df = df.update({old_name : new_name}, axis=‘bar’)

MCQ
Advertisements

उत्तर

df = df.rename({old_name : new_name}, axis=‘columns’)

Explanation:

In Pandas, the rename() function is used to modify column names in a DataFrame. Syntax: df = df.rename({old_name: new_name}, axis='columns')

  • A dictionary in the form {old_name: new_name} is provided to rename selected columns.
  • The parameter axis='columns' (or axis=1) indicates that the changes apply to column labels.
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2024-2025 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×