简体   繁体   中英

Indexing new column for boxplot of pandas dataframe

I have a large data set which I need to read in as Pandas Dataframe.

Subtract 2 columns containing price information (as floats)

Then plot the difference in prices on a boxplot (based on the time grouping they belong in)

I am struggling to get the 'new column' to index and be read as a 'float' to plot it correctly and I am also getting the error

Value is trying to be set on a copy of a slice from a     
DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

I need to understand how to make sure the 'New column' is a float and can be indexed for my Boxplot function to plot correctly.

BXdf['priceDelta'] = BXdf.searchPrice.fillna(BXdf.bookedPrice)
BXdf['priceDelta'] = BXdf[[ 'searchPrice']].subtract(BXdf['bookedPrice']
                                                     , axis=0)

a = BXdf.boxplot(column='priceDelta' ,by='timebucket',sym='k+',vert=False
                        ,widths=0.8,notch=True,bootstrap=1000,figsize=[24,12])

The Boxplot plots, but gives 0 values for all the subsets

print(BXdf['priceDelta'].head)

Gives

Name: priceDelta, dtype: float64>

I have a feeling it is something to do with .loc or reseting the index in the pricedelta column, but I am really struggling to resolve it.

Thanks

尝试:

BXdf['priceDelta'] = BXdf['searchPrice'] - BXdf['bookedPrice']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM