Vra

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'

Was dit nuttig?

Oplossing

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
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top