Reputation: 63082
Given a simple dataframe
:
lendf = pd.read_csv('/git/opencv-related/audio_and_text_files_lens.csv',
names=['path','duration'])
I need to do a simple operation on the first column:
lendf['path'] = lendf['path'].replace('.wav','.txt')
Let us check the result:
print(lendf['path'][:10])
So then nothing happened - we still have .wav
in there instead of .txt
. I am following a number of references including a simple one here: Pandas Apply function on Column. That answer provides the same pattern:
You can just do
df['B'] = df.B.notnull()
.
So why were the values not updated - and what is the correction to this code?
Upvotes: 1
Views: 41
Reputation: 2624
You may want str.replace
not replace
.
Use this code.
lendf['path'].str.replace('.wav', '.txt')
Upvotes: 2