我正在尝试使用与该行对应的索引值访问行号。
mydata = [{'name': 'John', 'age': 75, 'height':1.78},
      {'name': 'Paul', 'age': 22, 'height':1.71}]
df = pandas.DataFrame(mydata)
df = df.set_index('name')
获取第 1 行的索引值
index_value = df.index[1]
有了该索引值,我该如何返回行号?在这种情况下,1。
在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')
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]')
如果有一个数据框,其中的索引是日期,我将如何添加一个新的列,列名为“月”,该列是该月所有值的总和,但不会“输入未来”,因为它只会累加日期之前的几天。
这就是该列的外观。
'Month': [4, 3, 12]