我有一个csv要处理的文件pandas。该列称为raw_value我想检索该列中的唯一字符。
x=df.manual_raw_value.unique()\nRun Code Online (Sandbox Code Playgroud)\n\n允许检索唯一的行。但是,我希望检索此列中的整个字符。\n即:\nalphabet= 6 , 3 5 1 8 VOTREA 2 。\xc3\xa9 \xc3\xa8 / :
\n\n raw_value\n 6,35\n 11,68\n VOTRE\n AVEL AR VRO\n 2292\n questions.\n nb\n les\n 937,99\n \xc3\xa0\n et\n TTC\n 1\n 620\n Ech\xc3\xa9ance\n vos\n ROB21\n Pi\xc3\xa8ce\n AGRIAL\n d\xc3\xa9signation\n des\n taux\n 13s\n 2\n par\n le\n mois,\n 32\n 21/07/2016\n FR\n au\n 0\n t\xc3\xa9l\xc3\xa9phonique\n BROYEUR\n et\n ST\n TVA\n de\n des\n ECHEANCIER\n \xc3\xa0\n ne\n lieu\n 481,67\n N\xc2\xb00016\n de\n minist\xc3\xa8re\n de\n 20/11/2015\n Si\n vous\n 59\n cas\n …Run Code Online (Sandbox Code Playgroud) 我有这个函数可以与 python2 完美配合
def writeCache(env, cache):
with env.begin(write=True) as txn:
for k, v in cache.items():
txn.put(k, v)
Run Code Online (Sandbox Code Playgroud)
但是,当我执行它时,python3.5.2它会返回以下错误:
txn.put(k, v)
TypeError: Won't implicitly convert Unicode to bytes; use .encode()
Run Code Online (Sandbox Code Playgroud)
首先尝试解决这个问题:
def writeCache(env, cache):
with env.begin(write=True) as txn:
for k, v in cache.items():
k.encode()
Run Code Online (Sandbox Code Playgroud)
有效,但不包括变量 v 。
def writeCache(env, cache):
with env.begin(write=True) as txn:
for k, v in cache.items():
k.encode()
v.encode()
Run Code Online (Sandbox Code Playgroud)
我得到以下信息:
AttributeError: 'bytes' object has no attribute 'encode'
Run Code Online (Sandbox Code Playgroud)
这与 v.encode()
我对宽度和高度参数有点困惑:
高度是第一个参数还是第二个参数?
HEIGHT,WIDTH= img.shape[0:2] 或者 WIDTH,HEIGHt= img.shape[0:2]
并在调整大小功能height=32 and width=100或相反?
image=cv2.resize(img, (32, 100), interpolation=cv2.INTER_NEAREST)
Run Code Online (Sandbox Code Playgroud) 我想比较我创建新列的两列的值bin_crnn.如果他们是等于我想要1,否则想要0.
# coding: utf-8
import pandas as pd
df = pd.read_csv('file.csv',sep=',')
if df['crnn_pred']==df['manual_raw_value']:
df['bin_crnn']=1
else:
df['bin_crnn']=0
Run Code Online (Sandbox Code Playgroud)
我得到以下错误
if df['crnn_pred']==df['manual_raw_value']:
File "/home/ahmed/anaconda3/envs/cv/lib/python2.7/site-packages/pandas/core/generic.py", line 917, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud) dataframe ×2
pandas ×2
python ×2
byte ×1
encode ×1
opencv ×1
python-2.7 ×1
python-3.5 ×1
transactions ×1
unicode ×1