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
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
2Trướ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]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
8In [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
9rise_p['ts'] = [rise_p.time / 100].astype['int']
ts_grouped = rise_p.groupby['ts']
...
0In [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
9rise_p['ts'] = [rise_p.time / 100].astype['int']
ts_grouped = rise_p.groupby['ts']
...
2In [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
9rise_p['ts'] = [rise_p.time / 100].astype['int']
ts_grouped = rise_p.groupby['ts']
...
4new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
5new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7rise_p['ts'] = [rise_p.time / 100].astype['int']
ts_grouped = rise_p.groupby['ts']
...
8In [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
9In [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
0In [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
9In [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
2In [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
9In [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
4In [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
5new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
8In [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
9In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
0In [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
9In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
2In [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
9In [7]: df['time'] = pd.to_datetime[df['time'],unit='s']
4new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
5In [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
4new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
8In [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
9In [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
0In [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
9In [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
2In [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
9In [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
4new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
5new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
8In [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
9rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
0In [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
9rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
2In [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
9rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
4rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5Is
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
11Các
6rise_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
8rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5In [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
00In [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
6In [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
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
03In [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
9In [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
05In [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
9In [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
07__Converting one column from float to int using 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
2In [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
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
13Các
6rise_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
8rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5In [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
00In [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
6In [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
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
03In [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
9In [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
05In [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
9In [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
07__Converting more than one column from float
to int using 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
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
2In [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
13Các
6rise_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
8rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5In [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
00In [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
6In [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
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
03In [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
9In [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
05In [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
9In [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
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
Đầ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
2In [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
14In [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
07In [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
14In [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
07In [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
20In [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
6In [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
22new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
58In [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
9In [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
60In [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
9In [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
62In [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
49In [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
64In [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
9In [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
66In [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
9In [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
68new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
5new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
0In [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
9In [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
74In [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
9In [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
76In [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
49In [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
78In [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
9In [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
80In [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
9In [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
82new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
5new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
6new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
7In [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
86In [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
9In [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
88In [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
9In [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
90rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5Ví 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
2rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
6In [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
28In [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
29In [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
30In [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
31In [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
9In [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
33In [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
30In [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
31In [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
36In [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
11Các
6rise_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
8rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5In [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
00In [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
6In [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
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
03In [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
9In [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
05In [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
9In [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
07__Converting a single column from float to int using
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
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
13Ví 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
2In [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
13Các
6rise_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
8rise_p['ts'] = [rise_p.time / 100].apply[lambda val: int[val]]
5In [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
00In [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
6In [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
7new_re_df = [s.iloc[np.where[ts.astype[int] == int[i]]] for i in ts]
03In [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
9In [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
05In [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
9In [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
07__Converting multiple columns from float to int using 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
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
24In [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
13Ví 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
2In [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
14In [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
07In [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
14In [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
07In [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
20In [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
6In [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
22In [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
13Các