문제

I have the foll dataframe (grp):

key  ColA   ColB
2    23.4   33.4
3    43.2   45.3
4    12.3   90.3
5    11.2   77.3

grp is the result of a groupby operation performed earlier. Here 'key' is the index.

How can I create another dataframe with 'key' and 'ColA' as its elements? Right now, I cannot seem to select 'key'

도움이 되었습니까?

해결책

You can use reset_index. Assuming grp is the DataFrame as you have described:

res = grp['ColA'].reset_index()
# res is now a DataFrame with key and ColA as the columns
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top