我将数据文件的一部分切片,只保留两列。
description_category = titles[['listed_in','description']]摘录是这样的
description_category.head()
Listed_in description
0 International TV Shows, TV Dramas, TV Sci-Fi &... In a future where the elite inhabit an island ...
1 Dramas, International Movies After a devastating earthquake hits Mexico Cit...
2 Horror Movies, International Movies When an army recruit is found dead, his fellow...
3 Action & Adventure, Independent Movies, Sci-Fi... In a postapocalyptic world, rag-doll robots hi...
4 Dramas A brilliant group of students become card-coun...我想要做的是在"Listed_in“专栏中插入每个主题,所以看起来是这样的:
listed_in description
0 [International TV Shows, TV Dramas, TV Sci-Fi ... In a future where the elite inhabit an island ...
1 [Dramas, International Movies] After a devastating earthquake hits Mexico Cit...
2 [Horror Movies, International Movies] When an army recruit is found dead, his fellow...
3 [Action & Adventure, Independent Movies, Sci-F... In a postapocalyptic world, rag-doll robots hi...
4 [Dramas] A brilliant group of students become card-coun...我试过了,但它给了我一个警告:
description_category['listed_in'] = description_category['listed_in'].apply(lambda x: x.split(', '))警告:
C:\Anaconda\envs\nlp_course\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
"""Entry point for launching an IPython kernel.我在这个问题上检查了几个线程,但我仍然无法修复它。
你建议我怎么做?
如果你需要更多关于我问题的背景资料,请告诉我。
发布于 2021-07-03 16:24:25
如果您想在保留titles的同时创建一个新的数据格式,那么
.loc[]切片:'description'] = description_category = titles.loc[:,'listed_in',
.copy():description_category =标题[‘listed_in’,description_category
另外,使用.str.split()而不是apply()更快
description_category['listed_in'] = description_category['listed_in'].str.split(', ')发布于 2022-02-27 02:29:04
试试这个..。会成功的!!用DataFrame.loc‘结束整个任务
description_category.loc[description_category['listed_in'] = description_category['listed_in'].apply(lambda x: x.split(', '))]它不会显示任何警告
https://stackoverflow.com/questions/68237941
复制相似问题