小编use*_*407的帖子

通过索引访问行号

我正在尝试使用与该行对应的索引值访问行号。

mydata = [{'name': 'John', 'age': 75, 'height':1.78},
      {'name': 'Paul', 'age': 22, 'height':1.71}]

df = pandas.DataFrame(mydata)
df = df.set_index('name')
Run Code Online (Sandbox Code Playgroud)

获取第 1 行的索引值

index_value = df.index[1]
Run Code Online (Sandbox Code Playgroud)

有了该索引值,我该如何返回行号?在这种情况下,1。

python pandas

4
推荐指数
1
解决办法
4234
查看次数

解析html以获取特定的脚本类型

在html代码中,Vine <script type="application/ld+json">在页面上具有指向所有视频的链接,我如何访问此JSON?

import requests
from bs4 import BeautifulSoup

url = 'https://vine.co/tags/funny'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'html.parser')
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup html-parsing vine

2
推荐指数
1
解决办法
1482
查看次数

同月的值总和

data = {'dates': ['2010-01-29', '2011-06-14', '2012-01-18'], 'values': [4, 3, 8]}
df = pd.DataFrame(data)
df.set_index('dates')
df.index = df.index.astype('datetime64[ns]')
Run Code Online (Sandbox Code Playgroud)

如果有一个数据框,其中的索引是日期,我将如何添加一个新的列,列名为“月”,该列是该月所有值的总和,但不会“输入未来”,因为它只会累加日期之前的几天。

这就是该列的外观。

'Month': [4, 3, 12] 
Run Code Online (Sandbox Code Playgroud)

python pandas

2
推荐指数
1
解决办法
3108
查看次数

标签 统计

python ×3

pandas ×2

beautifulsoup ×1

html-parsing ×1

vine ×1