我如何在同一列中与Python中的单独列中进行两个值​
in this commands;
import requests
import pandas as pd
url = "https://api.binance.com/api/v3/depth?symbol=BNBUSDT&limit=100"
payload = {}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload).json()
depth = pd.DataFrame(response, columns=["bids","asks"])
print(depth)
输出:
........ | 投标 | 询问 |
---|---|---|
0 | [382.40000000,86.84800000] | [382.50000000,196.24600000] |
1 | [382.30000000,174.26400000] | [382.60000000,116.10300000], |
并且首先我需要更改桌子
。 .. | bidsValue | bidsQuantity | asksValue | asksQuantity | rangeTotalbidsQuantity | rangeTotalasksQuantity |
---|---|---|---|---|---|---|
0 | 382.40000000 | 86.84800000 | 382.50000000 | 196.24600000 | ||
1 | 382.30000000 | 174.26400000 | 382.60000000 | 116.10300000 |
and then turn the columns values float so that be able to calculate in a specific range values quantity (例如0bidsvalue 400.00和?bidsvalue 380.00(“?”,因为我不知道行号)首先,我必须找到BidsValue 380.00的行号(例如,它是59),然后计算0bidssquantity to 59 bidsquantity to 59 bidsquantity 和Last 在rangetalbidsquantity列中写下结果。
我已经尝试了几个小时,我尝试了许多来自“ pandas.dataframe”的命令,但我做不到。 谢谢你!
in this commands;
import requests
import pandas as pd
url = "https://api.binance.com/api/v3/depth?symbol=BNBUSDT&limit=100"
payload = {}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload).json()
depth = pd.DataFrame(response, columns=["bids","asks"])
print(depth)
outputs :
........ | bids | asks |
---|---|---|
0 | [382.40000000, 86.84800000] | [382.50000000, 196.24600000] |
1 | [382.30000000, 174.26400000] | [382.60000000, 116.10300000] |
and first i need to change the table this format
........ | bidsValue | bidsQuantity | asksValue | asksQuantity | rangeTotalbidsQuantity | rangeTotalasksQuantity |
---|---|---|---|---|---|---|
0 | 382.40000000 | 86.84800000 | 382.50000000 | 196.24600000 | ||
1 | 382.30000000 | 174.26400000 | 382.60000000 | 116.10300000 |
and then turn the columns values float so that be able to calculate in a specific range values quantity (e.g 0bidsValue 400.00 and ?bidsValue 380.00 ("?" because of i don't know row number) first i must find row number of bidsValue 380.00 (for example it is 59) then calculate 0bidsQuantity to 59bidsQuantity) and last write the results in rangeTotalbidsQuantity column.
I've been trying for hours, I tried many commands from "pandas.Dataframe" but I couldn't do it.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用此解决方案。
在您的情况下,这将看起来像这样:
第二部分查看此教程。
You can use this solution.
In your case this would look something like this:
For the second part look at this tutorial.
您可以使用:
然后将其连接到原始数据框架上。
You can use for example:
Then concatenate that to the original dataframe.
您可以
apply()
pandas.Series
并分配给新列,然后您必须删除原始列
bids,ask ass ass
与其他其他工作代码完整的工作代码更改
You can
apply()
pandas.Series
and assign to new columnsand later you have to remove original columns
bids,asks
Full working code with other changes