Jupyter Notebook Named Groups issue on extract() function
Turns out that Pycharm returns df_new_8 = dfnew['text'].str.extract(r'(?P\d{4})') as a DataFrame, where Jupyter notebook returns it as a Series.
I'm building a text analysis program that extract dates from a text document. The dates are in several formats so I have written several extract lines like below.
df_new_1 = dfnew['text'].str.extract(r'(?P\d{1,2})/-/-')
df_new_7 = dfnew['text'].str.extract(r'(?P\d{1,2})/-')
df_new_8 = dfnew['text'].str.extract(r'(?P\d{4})')
When running these lines in PyCharm, they work as expected. But, when running these in Jupyter Notebook, the last line (df_new_8) doesn't show the Grouped Name.
Output PyCharm of df_new_8.tail():
Year
495  1979
496  2006
497  2008
498  2005
499  1980
Output Jupyter Notebook of df_new_8.tail() No column title!!:
Out[1]
495    1979
496    2006
497    2008
498    2005
499    1980
Name: Year, dtype: object
To illustrate, when running df_new_1.head() in Jupyter it outputs (as expected):
Out[3]
Month   Day Year
0   03  25  93
1   6   18  85
2   7   8   71
3   9   27  75
4   2   6   96
At the end of the program I 'concatenate' all df_new* dataframes together using fillna.
df_out = df_new_1.fillna(df_new_2).fillna(df_new_3).fillna(df_new_4).fillna(df_new_5).fillna(df_new_6).fillna(df_new_7).fillna(df_new_8).fillna(1)
That's when the real problem appears in Jupyter Notebook. Obviously df_new_8 wasn't processed, probably because of the missing Named Group. Again, this works fine in PyCharm. So, instinctly I say there's a problem with the line:
df_new_8 = dfnew['text'].str.extract(r'(?P\d{4})')
Can't figure out what though.