我有一个新闻标题df
的数据帧,具体取决于时间,来源为Australian Financial Review, Financial Times, Reuters, The Times of India
列。每天都是行,给定的列/源具有当天标题的列表。
Australian Financial Review Financial Times Reuters The Times of India
date
2019-01-15 NaN [Hammond raises Article 50 delay to reassure b... [Manafort claimed to be placing people in Trum... [The Latest: Iowa's largest newspaper calls on...
2019-01-14 NaN [Ford and Volkswagen to deepen ties, Fast Asia... [Australia's IOOF flags delay in ANZ pension b... [Military help to Taiwan: China warns India, U...
...
我想将各列合并为一个列,其中包含给定日期的标题列表。就是说:
articles
2007-01-01 What Sticks from '06. Somalia Orders Islamist...
2007-01-02 Heart Health: Vitamin Does Not Prevent Death ...
2007-01-03 Google Answer to Filling Jobs Is an Algorithm...
2007-01-04 Helping Make the Shift From Combat to Commerc...
2007-01-05 Rise in Ethanol Raises Concerns About Corn as...
我尝试使用.merge
:
df_merging = df
df_merging = df_merging.drop(['Australian Financial Review', 'Financial Times', 'Reuters', 'The Times of India'], axis=1).assign(New_Column=
df_merging[['Australian Financial Review', 'Financial Times', 'Reuters', 'The Times of India']].agg(pd.Series.to_dict, axis=1))
但是它给了我一本字典,而且别忘了标题:
New_Column
date
2019-01-15 {'Australian Financial Review': nan, 'Financia...
2019-01-14 {'Australian Financial Review': nan, 'Financia...
2019-01-13 {'Australian Financial Review': nan, 'Financia..