我想将此代码编写为pythonic。我的实际数组比此示例大得多。
(5 + 10 + 20 + 3 + 2)/ 5
print(np.mean(array,key = lambda x:x [1]))TypeError:mean()得到了意外的关键字参数'key'
array = [('a', 5) , ('b', 10), ('c', 20), ('d', 3), ('e', 2)]
sum = 0
for i in range(len(array)):
sum = sum + array[i][1]
average = sum / len(array)
print(average)
import numpy as np
print(np.mean(array,key=lambda x:x[1]))
Run Code Online (Sandbox Code Playgroud)
如何避免这种情况?我想用第二个例子。
我正在使用Python 3.7
我想通过 SSH 连接我的 ec2。但我收到这个错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'F:\\Config\\first1.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "F:\\Config\\first1.pem": bad permissions
ec2-user@ec2-52-14-94-38.us-east-2.compute.amazonaws.com: Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
我如何在 Windows 上解决这个问题?
我想安装 tensorflow 以使用 Keras LSTM 我安装了 Keras,并将此行导入到我的代码中。
from keras.callbacks import LambdaCallback
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.layers import LSTM
from keras.optimizers import RMSprop
Run Code Online (Sandbox Code Playgroud)
错误是运行代码时:
No module named 'tensorflow'
Run Code Online (Sandbox Code Playgroud)
当我写“pip install tensorflow”时出现 Cmd 错误:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
Run Code Online (Sandbox Code Playgroud)
pip 版本是 19.3 ,python 版本 3.7
我正在尝试用远大的期望。
我想使用的功能是expect_compound_columns_to_be_unique. 这是代码(主代码 - 模板):
import datetime
import pandas as pd
import great_expectations as ge
import great_expectations.jupyter_ux
from great_expectations.core.batch import BatchRequest
from great_expectations.checkpoint import SimpleCheckpoint
from great_expectations.exceptions import DataContextError
context = ge.data_context.DataContext()
# Note that if you modify this batch request, you may save the new version as a .json file
# to pass in later via the --batch-request option
batch_request = {'datasource_name': 'impala_okh', 'data_connector_name': 'default_inferred_data_connector_name', 'data_asset_name': 'okh.okh_forecast_prod', 'limit': 1000}
# Feel free to change the name of …Run Code Online (Sandbox Code Playgroud) 我想在 oracle 中将数据帧(熊猫)附加到我的表中。但是这段代码删除了表中的所有行:(
我的数据框和我的结果变成了这样:
0, 0, 0, ML_TEST, 0, 5
0, 0, 0, ML_TEST, 0, 6
Run Code Online (Sandbox Code Playgroud)
通过下面的代码块:
import cx_Oracle
import pandas as pd
from sqlalchemy import types, create_engine
dataset = pd.read_csv("denemedf.txt", delimiter=",")
print(dataset)
from sqlalchemy import create_engine
engine = create_engine('oracle://***:***@***:***/***', echo=False)
dataset.to_sql(name='dev_log',con=engine ,if_exists = 'append', index=False)
Run Code Online (Sandbox Code Playgroud)
如何在不删除此表中现有行的情况下将此数据框的行附加到表的最后一个?
现在我再次尝试,现在附加到最后,但在第一次尝试时它删除了所有现有的行。如何有效地做到这一点而不引起任何问题?
实际上,由于该表的架构而出现问题。该表在 gnl 所有者中,但我与 prg 连接。所以它找不到表并创建了另一个表。有没有办法将所有者或架构写入此函数?
我有一列,我想找到 10 到 100 之间的长度(例如)
len(data[ 10 < data['TAHSILAT_DEGISIM_DEGER'] <= 100] )
Run Code Online (Sandbox Code Playgroud)
错误是:系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
class foo:
#initially
def __init__(self):
self.nodes1=[]
self.nodes2=[]
self.edges=[]
def add_node(self,type,x,y):
if type==1:
self.nodes1.append(node1(x,y))
class node1:
def __init__(self,x,y): #Getting coordinates from outside while creating the class.
self.x=x
self.y=y
b_foo = foo
b_foo.add_node(b_foo,1,0,1)
Run Code Online (Sandbox Code Playgroud)
我尝试在类的数组中添加一个元素.此代码给出如下错误:
AttributeError:类型对象'bipartite'没有属性'nodes1'
python ×6
arrays ×2
pandas ×2
amazon-ec2 ×1
average ×1
class ×1
dataframe ×1
keras ×1
lstm ×1
oracle ×1
python-3.x ×1
sql ×1
ssh ×1
tensorflow ×1
tuples ×1