Edit Type Of Column To Fixed Width String (within Existing Pandas Dataframe)
I have a column of string objects in a pandas dataframe. I'd like to change them to the a less outrageously inefficient fixed width string type. There are many SO answers (How to
Solution 1:
You can pop
the column before re-assignment:
In [11]: df.dtypes
Out[11]:
c object
dtype: object
In [12]: df['c'] = df.pop('c').astype('|S2')
In [13]: df.dtypes
Out[13]:
c |S2
dtype: object
Post a Comment for "Edit Type Of Column To Fixed Width String (within Existing Pandas Dataframe)"