Numpy'无法将字符串转换为浮动'

时间:2018-03-24 18:04:39

标签: python numpy

我有一个csv文件,其中包含第一列中的值,包括“1m4.5f”等字符串的变体。

当我尝试使用

data = np.loadtxt(f, delimiter=',')

我收到错误:

could not convert string to float: '"1m4.5f"'

我看不出.5是个问题?

谢谢,

1 个答案:

答案 0 :(得分:0)

Const myDB As String = "tenant" Const myServer As String = "MPAADM" Const myDB As String = "new" Const myServer As String = "arjun" Sub ExportTableToSQL() Dim cn As ADODB.Connection Dim cnSQL As ADODB.Connection Dim strSQL As String Dim lngRecsAff As Long Dim sqlTable As String Dim acell As Range Dim t1 As Date Dim t2 As Date Dim column As String On Error Resume Next path = Sheets("Sheet2").Range("B1").Value Kill path & \z_temp\aa.xls" Kill path & "\z_temp\aa.xls" On Error GoTo 0 On Error GoTo 10 column = Cells(1, 1).Value sqlTable = InputBox("Insert SQL table name") Application.Wait (Now + TimeValue("0:00:2")) t1 = Now Debug.Print t1 If sqlTable = "" Then Exit Sub Application.ScreenUpdating = False Set acell = ActiveCell If IsEmpty(ActiveCell) Then MsgBox "Select a cell inside a table you want to export to SQL" Exit Sub End If ActiveCell.CurrentRegion.Select Selection.Copy Call NewWorkbook Cells(1, 1).Select ActiveSheet.Paste Set cn = New ADODB.Connection Set cnSQL = New ADODB.Connection With cnSQL .ConnectionString = "provider=sqloledb;Data Source=" & myServer & ";Initial Catalog=" & myDB & ";Trusted_Connection=Yes" ' .ConnectionString = "provider=sqloledb;Data Source=" & myServer & ";Initial Catalog=" & myDB & ";Uid=jayantuser;Pwd=Input@123" .Open End With ActiveWorkbook.SaveAs path & "\z_temp\aa.xls" cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _ "Data Source=" & path & "\z_temp\aa.xls;" & _ "Extended Properties=Excel 12.0" strSQL = "drop table " & sqlTable Debug.Print strSQL On Error Resume Next cnSQL.Execute strSQL, lngRecsAff, adExecuteNoRecords Err.Clear On Error GoTo 10 strSQL = "SELECT * INTO [odbc;Driver={SQL Server};" & _ "Server=" & myServer & ";Database=" & myDB & _ ";trusted_connection=yes]." & sqlTable & _ " FROM [sheet1$]" Debug.Print strSQL cn.Execute strSQL, lngRecsAff, adExecuteNoRecords cn.Close Set cn = Nothing ActiveWorkbook.Close False On Error Resume Next Kill path & "\z_temp\aa.xlx" On Error GoTo 0 t2 = Now Debug.Print t2 MsgBox sqlTable & " table was successfully imported into SQL Server" & vbNewLine & "Transfered record number: " & lngRecsAff _ & vbNewLine & "Time:" & Int((t2 - t1) * 86400) & "s" If MsgBox("Convert data type to bigint?", vbYesNo) = vbYes Then strSQL = "ALTER TABLE " & sqlTable & " ALTER COLUMN " & column & " bigint" cnSQL.Execute strSQL, lngRecsAff, adExecuteNoRecords End If Application.ScreenUpdating = True acell.Select Exit Sub 10: MsgBox Err.Description End Sub `Sub NewWorkbook() Application.DefaultSaveFormat = xlOpenXMLWorkbook Workbooks.Add End Sub` `Sub Quit() Application.Quit End Sub` np.genfromtxt

一起使用

<强>实施例

dtype=None

<强> MoreInfo