Traceback (most recent call last):
File "/home/Py_Process_Plots/master_lac.py", line 14, in process
value=tmp-val
File "/home/software/anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 524, in wrapper
arr = na_op(lvalues, rvalues)
File "/home/software/anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 475, in na_op
result[mask] = op(x[mask], _values_from_object(y[mask]))
TypeError: unsupported operand type(s) for -: 'str' and 'float'
我有两个文件first.csv和second.csv,在first.csv我有两个标题LAC和引用计数,second.csv没有标题可以是任意数字,但它将遵循一个格式,即一列LAC所有id,后跟时间日期序列,我需要从second.csv获取LAC(id)并在first.csv的LAC中搜索引用计数并减去second.csv的所有时间序列的值。您可以更好地理解预期的输出。
..., SysUtils;
type
EFileNotFoundException = class(Exception)
end;
function FindFileSize(const Filename: string): Int64;
var
sr : TSearchRec;
Err: Integer;
begin
Err := FindFirst(filename, faAnyFile and (not faDirectory), sr);
if Err = 0 then
begin
FindClose(sr);
if (sr.Attr and faDirectory) = 0 then
begin
Result := sr.Size;
Exit;
end;
Err := ERROR_FILE_NOT_FOUND;
end
if Err = ERROR_FILE_NOT_FOUND then begin
raise EFileNotFoundException.Create(filename + ' not found.');
end else begin
RaiseLastOSError(Err);
end;
end;
procedure TMyForm.Button1Click(Sender: TObject);
begin
Label1.Caption := IntToStr(FindFileSize('C:\path to\some file.ext'));
end;
这是我的代码
javax.mail:javax.mail-api:1.5.3
我收到此错误
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
credential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
mService = new com.google.api.services.gmail.Gmail.Builder(
transport, jsonFactory, credential)
.setApplicationName("Gmail API Application")
.build();
String accName = this.getIntent().getStringExtra("ACCOUNT");
Log.d("TienDH", "ViewActivity - acc : " + accName);
if (accName != null) {
credential.setSelectedAccountName(accName);
settings = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_ACCOUNT_NAME, accName);
editor.commit();
try {
MimeMessage mm = SendMailCtrl.createEmail(accName, "yaraht2011@gmail.com", "Test", "test send mail API");
SendMailCtrl.sendMessage(mService, accName, mm);
Log.d("TienDH", "sent mail");
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我的熊猫版本是0.16.2,numpy是1.9.2
请帮我解决问题。
答案 0 :(得分:0)
这有效:
df1 = pd.read_csv('First.csv', sep='\t', header=0, index_col=0)
df2 = pd.read_csv('Second.csv', sep='\t', header=0, index_col=0)
dfans = df2.subtract(df1.iloc[:,0], axis=0).dropna()
print(df1)
Reference_Count
LAC
1000 500
2222 1000
3333 500
5555 1000
9999 1500
print(df2)
10/08/15 00:00 10/08/15 01:00
LAC
1000 2000 2500
2222 3000 4000
print(dfans)
10/08/15 00:00 10/08/15 01:00
LAC
1000 1500 2000
2222 2000 3000
您需要将LAC作为索引。以下不起作用......
index_default = pd.read_csv('test.csv', sep='\t', header=0)
print(index_default)
LAC 10/08/15 00:00 10/08/15 01:00
0 2222 3000 4000
1 1000 2000 2500
dfans = index_default.subtract(df1.iloc[:,0], axis=0).dropna()
print(dfans)
Empty DataFrame
Columns: [LAC, 10/08/15 00:00, 10/08/15 01:00]
Index: []
但是以LAC为索引,它有效......
index_lac = pd.read_csv('test.csv', sep='\t', header=0, index_col=0)
print(index_lac)
10/08/15 00:00 10/08/15 01:00
LAC
2222 3000 4000
1000 2000 2500
dfans = index_lac.subtract(df1.iloc[:,0], axis=0).dropna()
print(dfans)
10/08/15 00:00 10/08/15 01:00
LAC
1000 1500 2000
2222 2000 3000