목록 크기가 일치하지 않는 목록의 결과를 사용하여 데이터 프레임을 만들 수 있기를 원합니다. 데이터가없는 곳에 "NULL", "N / A"또는 "0"을 표시하고 싶습니다.
이것은 내 열 이름입니다.
header = ['Group','Person in charge', 'Type of Service', 'Registered Care Categories*', 'Shared Rooms','Facilities & Service']
결과 및 결과에 대한 각 2 개 요소 목록의 첫 번째 요소는 헤더에 표시된 열의 이름에 해당합니다.
results = [['Group', 'MacIntyre'],['Person in charge', ' Vivienne Donald (Manager)'],
['Type of Service', 'good'],['Shared Rooms', '4']]
results1 = [['Group', 'Jameseson'], ['Type of Service', 'bad'],['Shared Rooms', '8']]
원하는 출력 : 아래 표 이미지
다음은 원하는 작업을 수행하는 한 가지 방법을 보여주는 예입니다.
import pandas as pd
# first, construct a dataframe containing your desired columns
columns = ['Group', 'Person in charge', 'Type of Service',
'Registered Care Categories*', 'Shared Rooms', 'Facilities & Service']
df = pd.DataFrame(columns=columns)
# then, store each of your results in a list, so that they can be iterated through
result1 = [['Group', 'MacIntyre'], ['Person in charge', ' Vivienne Donald (Manager)'],
['Type of Service', 'good'], ['Shared Rooms', '4']]
result2 = [['Group', 'Jameseson'], ['Type of Service', 'bad'], ['Shared Rooms', '8']]
results = [result1, result2]
# now, loop through your results using enumerate to create an index for that dataframe row
for index, result in enumerate(results):
# within each result, loop through the available data elements
for item in result:
# unpack the items in the list
column, value = item[0], item[1]
# store the value in the appropriate columns
df.loc[index, column] = value
# finally, inspect the dataframe
print(df)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다