我有一个看起来像这样的数据帧。
这里是我的前视图。
string the_date
-rw-r--r-- 12 30067 10224
-rw-r--r-- 64 30067 10224
-rw-r--r-- 64 30067 10224
我找了一行代码,或一对夫妇,将在“_”字符到一个名为“the_date”后场的日期分开,但只有当“the_date”为空。像这样的事情,我认为:
df_all_files = pd.DataFrame(df_all_files.string.str.rsplit('',1).tolist(), columns = ['string','the_date'])
假设你用大熊猫和DF变量是你上面的数据框,你可以尝试以下方法:
df.loc[df['the_date'].isnull(), 'the_date'] = df['string'].apply(lambda x:x.split('_')[-1])