This seems like something simple. But I've tried several different things and read probably a dozen StackOverflow questions that seemed related.
I have market data for crypto currnecies (BitCoin and others). The Order Book is a list of all the 'asks' and 'bids' for a given currency. I am wanting to store the data in a Pandas DataFrame. (I'm not stuck on using DFs just thought it might provide easier plotting down the road.)
So the setup right now is a DataFrame where the Rate (price) is the Index and it is a float. The quantity of coins available at that price is in a column named Amt.
When I get an update to the Amount at a given Rate I want to simply replace that value. Of all the possible solutions I found this option to be the most intuitive to me:
df.Amt[df.Rate == rate] = new_amt
While I don't get any errors from this, when I check to see if the Amt changes I find that it has not. I assume this is one of those copy/slice issues vs working on the DataFrame itself.
Example:
df.head()
Out[77]:
Rate Amt
0 0.018021 0.319033
1 0.018009 29.994000
2 0.017999 28.121000
3 0.018042 2.233781
4 0.018055 13.433394
df.Amt[df.Rate == 0.018021] = 20
df.head()
Out[79]:
Rate Amt
0 0.018021 0.319033
1 0.018009 29.994000
2 0.017999 28.121000
3 0.018042 2.233781
4 0.018055 13.433394
What am I missing? I've worked with DFs in the past to change whole columns but not generally just 1 row.
df.Rate == 0.018021or justdf.Ratex > 0.017 & x < 0.019isclose()that might help you.