- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
导入 .txt 文件时,出现以下错误:
Can't convert 'int' object to str implicitly
我按如下方式导入我的 .txt 文件:
activityHeaders = ['Type', 'AccountID', 'ConID', 'SecurityID', 'Symbol', 'BBTicker', 'Currency', 'BaseCurrency', 'TradeDate', 'SettleDate', 'TransactionType', 'Quantity', 'UnitPrice', 'GrossAmount', 'SECFee', 'Commission', 'NetInBase', 'FXRatetoBase', 'Other1', 'Other2', 'Description']
dfActivity = pd.read_csv(activityFileUrl, skiprows=[1], header=activityHeaders, error_bad_lines=False)
我的 .txt 文件如下所示:
"H","I000000","Activity","20100407","16:02:38","20100329","1.0"
"D","I000000","","","","","CAD","EUR","20100329","20100329","WITH","0","0","-14.88","0","0","0","-14.88","-10.8158","",,"CASH TRANSFER (INTERNAL)"
"D","I000000","","","","","AUD","EUR","20100328","20100328","ADJ","0","0","4","0","0","0","4","2.7211","",,"CLIENT FEE (U000001, Commission)"
"D","U000001","37036548","DE000A0F6MD5","PRA","STK","EUR","EUR","20100329","20100331","SELL","-300","7.776","-2332.8","0","-6","0","2326.8","2326.8","405346125","FI","TRADE PRAKTIKER BAU-UND HEIMWERK A"
我不明白 int
可能来自哪里。请注意,我使用 skiprows 和 error_bad_lines 跳过了第一行和最后一行。我也将 header 设置为 None,它返回了同样的错误。
最佳答案
如果需要列表 activityHeaders
的列名称,则需要将 header
更改为 names
。
df = pd.read_csv(StringIO(temp), names=activityHeaders, skiprows=1, error_bad_lines=False)
print (df)
Type AccountID ConID SecurityID Symbol BBTicker Currency \
D I000000 NaN NaN NaN NaN CAD EUR
D I000000 NaN NaN NaN NaN AUD EUR
D U000001 37036548.0 DE000A0F6MD5 PRA STK EUR EUR
BaseCurrency TradeDate SettleDate ... \
D 20100329 20100329 WITH ...
D 20100328 20100328 ADJ ...
D 20100329 20100331 SELL ...
Quantity UnitPrice GrossAmount SECFee Commission NetInBase \
D 0.000 -14.88 0 0 0 -14.88
D 0.000 4.00 0 0 0 4.00
D 7.776 -2332.80 0 -6 0 2326.80
FXRatetoBase Other1 Other2 Description
D -10.8158 NaN NaN CASH TRANSFER (INTERNAL)
D 2.7211 NaN NaN CLIENT FEE (U000001, Commission)
D 2326.8000 405346125.0 FI TRADE PRAKTIKER BAU-UND HEIMWERK A
[3 rows x 21 columns]
此外,如果不需要跳过第二行,请省略 skiprows
:
df = pd.read_csv(StringIO(temp), names=activityHeaders, error_bad_lines=False)
print (df)
Type AccountID ConID SecurityID Symbol BBTicker Currency \
0 H I000000 Activity 20100407 16:02:38 20100329 1.0
1 D I000000 NaN NaN NaN NaN CAD
2 D I000000 NaN NaN NaN NaN AUD
3 D U000001 37036548 DE000A0F6MD5 PRA STK EUR
BaseCurrency TradeDate SettleDate ... Quantity UnitPrice \
0 NaN NaN NaN ... NaN NaN
1 EUR 20100329.0 20100329.0 ... 0.0 0.000
2 EUR 20100328.0 20100328.0 ... 0.0 0.000
3 EUR 20100329.0 20100331.0 ... -300.0 7.776
GrossAmount SECFee Commission NetInBase FXRatetoBase Other1 \
0 NaN NaN NaN NaN NaN NaN
1 -14.88 0.0 0.0 0.0 -14.88 -10.8158
2 4.00 0.0 0.0 0.0 4.00 2.7211
3 -2332.80 0.0 -6.0 0.0 2326.80 2326.8000
Other2 Description
0 NaN NaN
1 NaN NaN
2 NaN NaN
3 405346125.0 FI
[4 rows x 21 columns]
关于python - Pandas .read_csv() : Can't convert 'int' object to str implicitly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43115791/
这是我的查询: INSERT INTO location_province(name, country) SELECT child.name ,location_country.id
尽管我看到 C++ 教程中广泛使用术语 implicit casting 来表示这样一个事实,即当您将某种类型分配给另一种类型时,类型的转换将自动(隐式)完成,但我经常听说应该叫implicit co
所有表格都在 utf_unicode_ci 中。 我这样做是为了检查 SELECT table_schema, table_name, column_name, character_set_name,
def MyFun(result: ListBuffer[(String, DateTime, List[(String, Int)])]): String = { val json = (r
我刚刚在 Postgres 中创建了一个表,并收到一条通知消息,我不完全理解隐式索引和序列。如有任何澄清,我们将不胜感激。 my_database=# CREATE TABLE sites my_da
我正在关注 Fernando Villalobos 的 React.js - A guide for Rails developers AirPair 教程。 这里的目标是使用 Rails 和 Rea
当我选择一个选项时,我有通过多选列表在 dbase 中搜索的代码我有这个错误: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (ut
我正在尝试使用 execl 调用来执行 kernel-space-driver (driver.c) 中的二进制文件此时(从第 850 行开始): if (!retval) {
我正在尝试在内核 3.13 上编译内核模块,但出现此错误: error: implicit declaration of function 'create_proc_read_entry' [-Wer
我检查了数据库表,发现它在 latin1_swedish_ci 中,所以我将其更改为 utf8_general_ci 然后我将排序规则从 latin1_swedish_ci 更改到所有字段的 utf8
尝试通过 MySQL 中的存储过程进行选择时出现以下错误 Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_ge
我收到了这个错误; Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT)
我需要您帮助确定为什么会出现此错误 Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT
我收到了这个错误; Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT)
MySql 上的错误信息: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) fo
在我的删除服务器上执行 MySQL 中的存储过程时,如下所示: CREATE OR REPLACE PROCEDURE `SetNextPage`( IN `inRefNo` varchar(
我正在尝试为 Kali linux 2.0 安装我的 Alfa AWUS036ACH 适配器 我已经修复了之前的错误,但现在我被困在这里了。这是错误我正在接收。 os_dep/linux/rtw_an
我们正在使用以下存储过程,并且所有提到的表都使用“Collation = utf8_general_ci”,但我们仍然收到此错误: Error Code: 1267. Illegal mix of
我想让我的 User 表的 password 列在 mysql 中区分大小写。 表的说明如下: /*Table: mst_user*/ FIELD TYPE
我对这一切都很陌生,正在尝试在内核版本为 3.10.0-957.el7.x86_64 的虚拟机上编译程序。但我收到此错误: /home/../../../isr_demux.c: In functio
我是一名优秀的程序员,十分优秀!