-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Closed
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselves
Description
Code Sample, a copy-pastable example if possible
import pandas as pd
df = pd.DataFrame({'Data': ['afoo abc: agsegsegs', 'b def: eafsegsg', 'c ghi:']})
df2 = df
df2.loc[:, 'foo2'] = df2.Data.fillna('').astype(str).str.extract(r'.*(\w{3}).*')
print df2['foo2']Problem description
When printing df2['foo2'] I get:
0 NaN
1 NaN
2 NaN
If instead I change the line assigning to 'foo2' to:
df2['foo2'] = df2.Data.fillna('').astype(str).str.extract(r'.*(\w{3}).*')When printing df2['foo2'] I get:
0 egs
1 gsg
2 ghi
I would have expected df.loc[:, 'foo2'] and df['foo2'] assignments to behave the same way.
Output of pd.show_versions()
pandas: 0.23.4
numpy: 1.15.4
python: 2.7.14.final.0
Metadata
Metadata
Assignees
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselves