如何将整个列表存储在列的单行中



我有多个不同长度的列表,例如:

列表1

['In addition to new financing, a coalition of organizations will provide technical assistance on a wide range of activities, including the mapping of restoration opportunities, securing further financing, and providing catalytic support for the implementation of restoration efforts on the ground.',
 'The main actors in implementation of restoration are farmers, herders, resource user groups, local leaders and other actors in rural communities, along with supporting stakeholders such as the private sector, NGOs and government agencies working at different levels.']

列表2

['African Union Development Agency (AUDA-NEPAD)',
 'Bioversity International',
 'Catholic Relief Services (CRS)',
 'CIFOR',
 'CIRAD',
 'Conservation International (CI)',
 'Deutsche Gesellschaft für Internationale Zusammenarbeit (GIZ)',
 'Ecoplanet Bamboo',
 'EverGreening Alliance',
 'Food and Agriculture Organization of the United Nations (FAO)',
 'Global Water Partnership Southern Africa',
 'Heinz Sielmann Stiftung',
 'International Center for Tropical Agriculture (CIAT)',
 'International Tree Foundation',
 'International Union for Conservation of Nature (IUCN)',
 'Jane Goodall Institute (JGI)',
 'Justdiggit']

我想将每个列表中的所有条目作为一个条目存储到一个列行中,因为这些列表代表一个类别,并且列表中的全部元素都分组在一个特定的类别下。

像这样:

Description | Organizations |
  List 1    |    List 2     |

我尝试过df[Organisations] = List2,但它将列表中的每个项目都视为一行的条目。

您可以执行以下操作:

#Create an empty dataframe with the columns you want
df = pd.DataFrame(columns = ["Description","Organizations"])
#Fill the columns
df.loc[0,"Description"] = list1
df.loc[0,"Organizations"] = list2

输出

Description                                         | Organizations
____________________________________________________|_______________
[In addition to new financing, a coalition of ...   |[African Union Development Agency (AUDA-NEPAD)...

您可以这样尝试:

df['Description'] = ','.join(list1)
df['Organizations'] = ','.join(list2)
List1= [contents]
List2 = [contents]
lstTotal = []
for i in range(len(List1)):
     newSection = [List1[i],List2[i]]
     lstTotal.append(newSection)

这将输出

lstTotal = [[description1,organization1],[description2,organization2],etc...]

最新更新