我正在学习本教程https://github.com/alexhuang1117/personal_projects/blob/master/pm25_analysis/notebooks/.ipynb_checkpoints/01_anomaly_detection_beijing_weather-checkpoint.ipynb import pandas as pd
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
from
我需要些帮助。想弄清楚到底是什么问题。
parse = json.loads(phoneget.text)
phoneNUM = parse["tel"] # gets phone number
phoneID = parse["idNum"] # gets id number
print(sms_config.key) # ignore this
print("Parse complete, here is your result:") # ignore this
在我的数据集中,我有一个列如下所示:
hist = ['A','FAT',nan,'TAH']
然后,我应该使用一个循环来获得包含一个 'A'的单元格。这是我的代码:
import numpy as np
import pandas as pd
import math
from numpy import nan
for rowId in np.arange(dt.shape[0]):
for hist in np.arange(10):
if mat
我正在用Python尝试一些东西。我想将一个列表(平台)分成几个列表(Li),但我收到了以下错误消息:
File "C:\Users\adescamp\Skycraper\skycraper.py", line 20, in <module>
item = plateau[debut:fin]
TypeError: slice indices must be integers or None or have an __index__ method
相关的行是带有item = plateau[debut:fin]的那行
from math import s
我的代码是:
b=[1215316235,1215316234,1210216096,1210716053]
for i in range(398):
a=b[i]
if a[0:5] == '12153':
print(a)
我收到一个错误:
TypeError Traceback (most recent call last)
<ipython-input-113-d3b104ffc744> in <module>()
1 for i in ran
这里的新Python用户。我试图让这段代码运行,这样用户在列表上输入他们想要的任何内容后,它就会输出列表中的值,减去最后一个。但是,我不能让它将最后一个值保留在列表之外;如果我使用我注释掉的最后一行代码,它会告诉我"TypeError:列表索引必须是整数或切片,而不是元组。
谁能给我指明正确的方向吗?
while True:
newWord = input("Enter a word to add to the list (press return to stop adding words) > ")
if newWord == ""
我正在尝试用Python语言编写一个简单的函数来做或str.contains中做的事情,下面是代码:
def contains(big, little):
length = len(little_string)
for i in big:
if big[i:i+length-1] == little:
return True
return False
对于line if big[i:i+length-1] == little:`` it throws a TypeError saying must be str not int,我很困惑。因为我认为,只要big是
我有一个JSON文件,我从中提取了一个列表。
我尝试使用列表索引从列表中获取其他项,但是我得到了这个错误。
TypeError:列表索引必须是整数或切片,而不是str。
for name in data['athletes'][0:]['athlete']['displayName']:
print(name)
如果我没有在索引中使用冒号,它将提取名称。
根据一些教程,我尝试根据从下拉菜单中选择的日期来过滤我的数据。我已经将date列设置为索引,并测试了所有值都是datetime类型,但我收到了以下错误:
TypeError("'<' not supported between instances of 'str' and 'datetime.date'",)
数据:
CustomerName,OrderDate,Item,ItemSKU,Price,Quantity,Channel,Total
Joe,Blog,26/09/2018,Rocks,Rock001,10.99,
我尝试了下面的代码,但是到目前为止它还没有起作用,它说我不能
names = ['John Johnson Doe', 'Jane Janis Doe']
firstnames = []
for name in names:
firstnames.append(names[name].split(' ')[0])
print(firstnames)
我在这里遇到的错误是:
TypeError: list indices must be integers or slices, not str
我正在修改一些代码,这些代码在通过列表理解声明的列表上调用枚举。
self.groups = [Groups(self, idx) for idx in range(n_groups)]
然后:
for idx, group in enumerate(self.groups):
# do some stuff
但是当我通过start参数将枚举调用更改为从第二个列表元素开始时,例如
for idx, group in enumerate(self.groups[1]):
我得到了一个异常:
exceptions.TypeError: 'Group' object is n
我正在尝试使用python进行一些数据操作和分析。我是python新手,在使用csv函数库加载数据时遇到了一些问题。我的代码:
import csv
out = open("data1.csv","rb")
data = csv.reader(out)
data = [row for row in data]
x = data[:,0]
生成以下错误:
Traceback (most recent call last):
File "/home/matthew/NumericalAnalysis.py", line 12, in <m
我得到了一个TypeError:
TypeError: '<' not supported between instances of 'datetime.date' and 'str'`
同时运行以下代码:
import requests
import re
import json
import pandas as pd
def retrieve_quotes_historical(stock_code):
quotes = []
url = 'https://finance.yahoo.com/quote
我正在读关于python切片的文章,但我不能理解这一点。 clf.predict_proba(X_test)[:,1] 然后我试着用简单的列表来测试自己。 a = [2,4,6,7,7,8]
>>> a[:,1]
-----> TypeError: list indices must be integers or slices, not tuple
我有个功能
function(input: str) -> Tuple[str, str]:
return tuple(x for x in input.split(","))
输入总是'value1,value1 2‘,但是,我得到了一个错误消息:"Tuplestr,.“,期望"Tuplestr,str")
是否有强制返回类型到预期的类型,只需使用一行代码?
我有一个用户user_list=["5c471d607f","5c63e9e46a","5c63e9e44e"]的列表,我正在尝试将它插入到mongodb中,以将其插入到mongodb中。我的代码是: for i in range(0,len(user_list)):
collection_4.update_one({'user_id':ObjectId(user_list[i])},{'$set':{'products': temp_list }},upsert=True)
This
我尝试使用以下内容提取一个制表符分隔文件的前几个元素:
words = []
name_elements = []
counter = 0
for line in f:
words = line.split()
for element in words:
counter = counter + 1
if words[element].isupper():
name_elements = words[0:counter-1]
print type(counter)
当我运行这段代码时,我得到了这个错误:
TypeError