I am using pandas (version 0.20.3) and I want to apply the diff()
method with groupby()
but instead of a DataFrame, the result is an "underscore".
Here is the code:
import numpy as np
import pandas as pd
# creating the DataFrame
data = np.random.random(18).reshape(6,3)
indexes = ['B']*3 + ['A']*3
columns = ['x', 'y', 'z']
df = pd.DataFrame(data, index=indexes, columns=columns)
df.index.name = 'chain_id'
# Now I want to apply the diff method in function of the chain_id
df.groupby('chain_id').diff()
And the result is an underscore!
Note that df.loc['A'].diff()
and df.loc['B'].diff()
do return the expected results so I don't understand why it wouldn't work with groupby()
.