You have an input CSV file in a source location. Read the file, drop an existing column, and add a new derived column that increases the salary by three times. Provide a code snippet.
1Times asked
Jun 2026Last seen
Jun 2026First seen
💡 Model Answer
Using pandas makes this task straightforward. The code reads the CSV, drops the unwanted column, creates a new column by multiplying the salary by 3, and writes the result back.
python
import pandas as pd
source = "/path/to/source/data.csv"
output = "/path/to/target/data_processed.csv"
# Read CSV
df = pd.read_csv(source)
# Drop a column named 'old_column'
df = df.drop(columns=['old_column'])
# Add derived column 'salary_increased'
df['salary_increased'] = df['salary'] * 3
# Write back to CSV
df.to_csv(output, index=False)Complexity is O(n) where n is the number of rows, as pandas processes the entire DataFrame in memory. If the file is large, consider using the csv module or chunked processing. This snippet assumes the salary column exists and contains numeric values.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500