I just wondering if there is any other way I can extract the year from a column and assign two new columns to it where one column is for season and one for year?
I tried this method and it seems to work, but only work for year and selected rows:
year = df['premiered'].str.findall('(\d{4})').str.get(0)
df1 = df.assign(year = year.values)
Output:
|premiered||year|
|----------||---|
|Spring 1998||1998|
|Spring 2001||2001|
|Fall 2016||NaN|
|Fall 2016||NaN|
source https://stackoverflow.com/questions/71444008/extract-seasons-and-years-from-a-string-column-in-pandas
Comments
Post a Comment