Hướng dẫn convert float series to int python - chuyển đổi chuỗi float thành int python

9

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi có khung dữ liệu sau:

In [31]: rise_p
Out[31]: 
         time    magnitude
0  1379945444   156.627598
1  1379945447  1474.648726
2  1379945448  1477.448999
3  1379945449  1474.886202
4  1379945699  1371.454224

Bây giờ, tôi muốn nhóm các hàng trong vòng một phút. Vì vậy, tôi chia chuỗi thời gian với 100. Tôi nhận được điều này:

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542

Như đã giải thích ở trên, tôi muốn tạo các nhóm dựa trên thời gian. Vì vậy, các nhóm nhỏ được mong đợi sẽ là các hàng có thời gian ____10 và

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
1. Tôi làm việc này:

In [37]: ts = rise_p['time']/100

In [38]: s = rise_p/100

In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
---------------------------------------------------------------------------
TypeError                                 Traceback [most recent call last]
 in []
----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]

TypeError: only length-1 arrays can be converted to Python scalars

Làm cách nào để chuyển đổi

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
2 thành chuỗi số nguyên vì int [] không lấy một chuỗi hoặc danh sách làm đối số? Có bất kỳ phương pháp trong gấu trúc mà làm điều này?

Hỏi ngày 26 tháng 9 năm 2013 lúc 11:14Sep 26, 2013 at 11:14

Thử chuyển đổi với ASTYPE:

new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]

Chỉnh sửa

Theo đề xuất của @Rutger Kassies Một cách đẹp hơn sẽ là để diễn ra loạt phim và sau đó là Groupby:

rise_p['ts'] = [rise_p.time / 100].astype['int']

ts_grouped = rise_p.groupby['ts']

...

Đã trả lời ngày 26 tháng 9 năm 2013 lúc 11:49Sep 26, 2013 at 11:49

C Marsc MarsC Mars

2.8274 Huy hiệu vàng20 Huy hiệu bạc 30 Huy hiệu Đồng4 gold badges20 silver badges30 bronze badges

2

Đây là một cách khác để giải quyết vấn đề của bạn

In [3]: df
Out[3]: 
         time    magnitude
0  1379945444   156.627598
1  1379945447  1474.648726
2  1379945448  1477.448999
3  1379945449  1474.886202
4  1379945699  1371.454224

In [4]: df.dtypes
Out[4]: 
time           int64
magnitude    float64
dtype: object

Chuyển đổi dấu thời gian kỷ nguyên của bạn thành giây

In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']

Đặt chỉ mục

In [8]: df.set_index['time',inplace=True]

In [9]: df
Out[9]: 
                       magnitude
time                            
2013-09-23 14:10:44   156.627598
2013-09-23 14:10:47  1474.648726
2013-09-23 14:10:48  1477.448999
2013-09-23 14:10:49  1474.886202
2013-09-23 14:14:59  1371.454224

Groupby 1min và có nghĩa là kết quả [

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
3 cũng có thể là một chức năng tùy ý]

In [10]: df.resample['1Min',how=np.mean]
Out[10]: 
                       magnitude
time                            
2013-09-23 14:10:00  1145.902881
2013-09-23 14:11:00          NaN
2013-09-23 14:12:00          NaN
2013-09-23 14:13:00          NaN
2013-09-23 14:14:00  1371.454224

Đã trả lời ngày 26 tháng 9 năm 2013 lúc 12:34Sep 26, 2013 at 12:34

JeffjeffJeff

Huy hiệu vàng 121K2020 gold badges212 silver badges184 bronze badges

2

Đây là một cách khá chung chung để chuyển đổi

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
2 thành
In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
5 loại
In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
6:

rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]

In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
7 cho phép bạn áp dụng hàm tùy ý cho giá trị đối tượng
In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
5 theo giá trị.
In [32]: rise_p/100
Out[32]: 
          time  magnitude
0  13799454.44   1.566276
1  13799454.47  14.746487
2  13799454.48  14.774490
3  13799454.49  14.748862
4  13799456.99  13.714542
7 cũng hoạt động trên các cột của đối tượng DataFrame.

Đã trả lời ngày 14 tháng 2 năm 2019 lúc 15:45Feb 14, 2019 at 15:45

winni2kwinni2kwinni2k

1.38215 huy hiệu bạc18 Huy hiệu đồng15 silver badges18 bronze badges

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luận

    Hãy cho chúng tôi xem làm thế nào để chuyển đổi float thành số nguyên trong khung dữ liệu gấu trúc. Chúng tôi sẽ sử dụng

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    0Method để làm điều này. Nó cũng có thể được thực hiện bằng phương pháp
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    1.

    Phương pháp 1: Sử dụng phương pháp

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    Trước hết, chúng tôi sẽ tạo một DataFrame:

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].astype['int']
    
    ts_grouped = rise_p.groupby['ts']
    
    ...
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].astype['int']
    
    ts_grouped = rise_p.groupby['ts']
    
    ...
    
    2
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].astype['int']
    
    ts_grouped = rise_p.groupby['ts']
    
    ...
    
    4
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    5

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    rise_p['ts'] = [rise_p.time / 100].astype['int']
    
    ts_grouped = rise_p.groupby['ts']
    
    ...
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [3]: df
    Out[3]: 
             time    magnitude
    0  1379945444   156.627598
    1  1379945447  1474.648726
    2  1379945448  1477.448999
    3  1379945449  1474.886202
    4  1379945699  1371.454224
    
    In [4]: df.dtypes
    Out[4]: 
    time           int64
    magnitude    float64
    dtype: object
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [3]: df
    Out[3]: 
             time    magnitude
    0  1379945444   156.627598
    1  1379945447  1474.648726
    2  1379945448  1477.448999
    3  1379945449  1474.886202
    4  1379945699  1371.454224
    
    In [4]: df.dtypes
    Out[4]: 
    time           int64
    magnitude    float64
    dtype: object
    
    2
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [3]: df
    Out[3]: 
             time    magnitude
    0  1379945444   156.627598
    1  1379945447  1474.648726
    2  1379945448  1477.448999
    3  1379945449  1474.886202
    4  1379945699  1371.454224
    
    In [4]: df.dtypes
    Out[4]: 
    time           int64
    magnitude    float64
    dtype: object
    
    4
    In [3]: df
    Out[3]: 
             time    magnitude
    0  1379945444   156.627598
    1  1379945447  1474.648726
    2  1379945448  1477.448999
    3  1379945449  1474.886202
    4  1379945699  1371.454224
    
    In [4]: df.dtypes
    Out[4]: 
    time           int64
    magnitude    float64
    dtype: object
    
    5

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [3]: df
    Out[3]: 
             time    magnitude
    0  1379945444   156.627598
    1  1379945447  1474.648726
    2  1379945448  1477.448999
    3  1379945449  1474.886202
    4  1379945699  1371.454224
    
    In [4]: df.dtypes
    Out[4]: 
    time           int64
    magnitude    float64
    dtype: object
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
    
    2
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
    
    4
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    5

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    3
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    4

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [8]: df.set_index['time',inplace=True]
    
    In [9]: df
    Out[9]: 
                           magnitude
    time                            
    2013-09-23 14:10:44   156.627598
    2013-09-23 14:10:47  1474.648726
    2013-09-23 14:10:48  1477.448999
    2013-09-23 14:10:49  1474.886202
    2013-09-23 14:14:59  1371.454224
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [10]: df.resample['1Min',how=np.mean]
    Out[10]: 
                           magnitude
    time                            
    2013-09-23 14:10:00  1145.902881
    2013-09-23 14:11:00          NaN
    2013-09-23 14:12:00          NaN
    2013-09-23 14:13:00          NaN
    2013-09-23 14:14:00  1371.454224
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [10]: df.resample['1Min',how=np.mean]
    Out[10]: 
                           magnitude
    time                            
    2013-09-23 14:10:00  1145.902881
    2013-09-23 14:11:00          NaN
    2013-09-23 14:12:00          NaN
    2013-09-23 14:13:00          NaN
    2013-09-23 14:14:00  1371.454224
    
    2
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [10]: df.resample['1Min',how=np.mean]
    Out[10]: 
                           magnitude
    time                            
    2013-09-23 14:10:00  1145.902881
    2013-09-23 14:11:00          NaN
    2013-09-23 14:12:00          NaN
    2013-09-23 14:13:00          NaN
    2013-09-23 14:14:00  1371.454224
    
    4
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    5

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [10]: df.resample['1Min',how=np.mean]
    Out[10]: 
                           magnitude
    time                            
    2013-09-23 14:10:00  1145.902881
    2013-09-23 14:11:00          NaN
    2013-09-23 14:12:00          NaN
    2013-09-23 14:13:00          NaN
    2013-09-23 14:14:00  1371.454224
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    2
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    4
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    5

    Is

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    11

    Các

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    5
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    00
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    03
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    05
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07__
    Converting one column from float to int using
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Đầu ra:

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Các

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    5
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    00
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    03
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    05
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07__
    Converting more than one column from float to int using
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Đầu ra:

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Các

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    5
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    00
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    03
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    05
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07__

    Đầu ra:

    Ví dụ 1: Chuyển đổi một cột từ phao sang int bằng cách sử dụng

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    14
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    16____26
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    14
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    20
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    6
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    22

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    58
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    60
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    62
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    49
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    64
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    66
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    68
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    5

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [8]: df.set_index['time',inplace=True]
    
    In [9]: df
    Out[9]: 
                           magnitude
    time                            
    2013-09-23 14:10:44   156.627598
    2013-09-23 14:10:47  1474.648726
    2013-09-23 14:10:48  1477.448999
    2013-09-23 14:10:49  1474.886202
    2013-09-23 14:14:59  1371.454224
    
    0
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    74
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    76
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    49
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    78
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    80
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    82
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    5

    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    86
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    88
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    90
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    5

    Ví dụ 2: Chuyển đổi nhiều hơn một cột từ phao sang int bằng cách sử dụng

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    28
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    29
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    30
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    31
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    33
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    30
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    31
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    36

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    11

    Các

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    5
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    00
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    03
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    05
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07__
    Converting a single column from float to int using
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    24

    Đầu ra:

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Ví dụ 1: Chuyển đổi một cột từ phao sang int bằng cách sử dụng

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Các

    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    6
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
    
    8
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    5
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    00
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    6
    new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
    
    7
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    03
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    05
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    9
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07__
    Converting multiple columns from float to int using
    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    24

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Ví dụ 1: Chuyển đổi một cột từ phao sang int bằng cách sử dụng

    In [37]: ts = rise_p['time']/100
    
    In [38]: s = rise_p/100
    
    In [39]: new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback [most recent call last]
     in []
    ----> 1 new_re_df = [s.iloc[np.where[int[ts] == int[i]]] for i in ts]
    
    TypeError: only length-1 arrays can be converted to Python scalars
    
    2

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    14
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    16____26
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    14
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    07
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    20
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    6
    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    22

    In [32]: rise_p/100
    Out[32]: 
              time  magnitude
    0  13799454.44   1.566276
    1  13799454.47  14.746487
    2  13799454.48  14.774490
    3  13799454.49  14.748862
    4  13799456.99  13.714542
    
    13

    Các


    Làm thế nào để bạn chuyển đổi float thành int in python?

    Một giá trị float có thể được chuyển đổi thành giá trị INT không lớn hơn đầu vào bằng cách sử dụng hàm math.floor [], trong khi nó cũng có thể được chuyển đổi thành giá trị INT là số nguyên nhỏ nhất lớn hơn đầu vào sử dụng math.ceil [] hàm số.by using the math.floor[] function, whereas it can also be converted to an int value which is the smallest integer greater than the input using math.ceil[] function.

    Làm thế nào để bạn chuyển đổi một loạt thành int in python?

    Làm thế nào để chuyển đổi loạt bài Pandas Core của lớp thành câu trả lời mã Int Int..
    astype [str] # biến đổi làm nhân vật ..
    astype [float] # biến đổi dưới dạng float ..
    astype [int] # biến đổi thành số ..

    Làm cách nào để thay đổi dtype từ phao sang int?

    Cách chuyển đổi phao sang số nguyên trong gấu trúc DataFrame..
    Cột DataFrame cụ thể bằng cách sử dụng ASTYPE [int] hoặc áp dụng [int].
    Toàn bộ DataFrame trong đó kiểu dữ liệu của tất cả các cột nổi ..
    DataFrame hỗn hợp trong đó kiểu dữ liệu của một số cột nổi ..
    DataFrame chứa các giá trị NAN ..

    Làm thế nào để bạn chuyển đổi tất cả các cột float thành int trong gấu trúc?

    Để chuyển đổi một cột bao gồm hỗn hợp các giá trị float và NAN thành int, trước tiên hãy thay thế các giá trị NAN bằng 0 trên gấu trúc DataFrame và sau đó sử dụng astype [] để chuyển đổi.Sử dụng DataFrame.fillna [] để thay thế các giá trị NAN bằng giá trị số nguyên bằng không.first replace NaN values with zero on pandas DataFrame and then use astype[] to convert. Use DataFrame. fillna[] to replace the NaN values with integer value zero.

    Bài Viết Liên Quan

    Chủ Đề