在pandas中将对象转换为int

时间:2020-05-07 22:54:13

标签: python pandas object int

我想将0.5%的列转换为int值(数据类型)

我有下表:

TIME                    BID      ASK    0.50%        1%
2020-05-02.20-16-32-016 8983.5  8984    2,946,165   4,334,669
2020-05-02.20-16-37-018 8983.5  8984    5,636,786   6,964,867
2020-05-02.20-16-42-053 8983.5  8984    6,637,055   8,058,007
2020-05-02.20-16-47-054 8981    8981.5  7,624,258   8,965,052
2020-05-02.20-16-52-054 8979.5  8980    7,858,870   8,835,523

我正在尝试从0.5%的列中获取特定值,但这是说它不是整数。

我有以下代码:

import pandas as pd
import numpy as np
import plotly.express as px

df = pd.read_csv('quotes.csv')
print(df.dtypes)
df['0.5%'] = df['0.5%'].astype(np.int64)

'df.dtypes'提供以下内容:

TIME          object
BID         float64
ASK         float64
0.5%         object
1%           object
dtype: object

我尝试用代码df['0.5%'] = df['0.5%'].astype(np.int64)转换0.5%的列,但它给了我一个错误invalid literal for int() with base 10: '2,946,165'

0 个答案:

没有答案