I am encountering a scenario where deleting/update columns of a pandas dataframe is required. What I get as a result is that the columns I am trying to delete, get deleted but when I export a new CSV file from the dataframe, I see new columns added that have the same data + data types of the columns I deleted. These new columns have names like Unnamed :0
, Unnamed: 0.1
, Unnamed: 0.1.1
, etc.
Here is the snippet that represents the procedure:
import pandas as pd
import numpy as np
df = pd.read_csv('./<some_file>.csv', encoding='unicode_escape')
del df['col']
df.to_csv('./<some_file>.csv')
df = pd.read_csv('./<some_file>.csv', encoding='unicode_escape')
Any ideas why I am encountering such a situation and whether what I am doing is correct?