Reputation: 17468
I have a Pandas DataFrame
and it has 11 columns, but I want to split the DataFrame from column 1, not column 0, to column 10. I can implement it by more complex method, not the method provided by Pandas
itself. How can I do it by using the DataFrame
method supported by Pandas
?
The data is 595 rows by 11 columns and I want to get :
>>> import numpy as np
>>> import pandas as pd
>>> train_data = pd.DataFrame(my_data, columns=my_columns)
>>> train_data
stockid prich_m1 prich_m3 prich_m6 \
1 000002.SZ 1.55755700445 0.861009772647 5.42726384781
2 000009.SZ 3.00223270244e-07 4.8010096027 4.46164511978
.. ... ... ... ...
.. ... ... ... ...
594 603699.SH 0.0491892903353 0.934596516371 0.0196757161342
595 603993.SH 0.83105321611 0.771692272102 2.02816558693
rsi mkt_cap held_by_ins found_own \
1 0.650879566982 153108876954.0 42.6353598479 14.9550575226
2 0.462085308057 19492802690.5 25.8866394448 5.31468116104
.. ... ... ... ...
.. ... ... ... ...
.. ... ... ... ...
594 0.482105263158 14580000000.0 3.98638909091 3.41028242424
595 0.559681697613 44416492093.8 90.0529786043 1.56995953686
debt_to_equity eps_rate share_out
1 4.4521 0.292628452536 11021632763.0
2 2.8257 -50.6773540796 1489669062.0
.. ... ... ...
.. ... ... ...
594 0.6798 1.48454654486 82500000.0
595 0.8822 10.3388360485 3279577050.0
[595 rows x 11 columns]
And I want to drop the stockid
column and get the rest data.
Upvotes: 3
Views: 15553
Reputation: 42885
Try
new_df = df.iloc[:, 1:]
there's also new_df = df.ix[:, 1:]
. This should eliminate stock_id
. If you want to drop this column then use new_df = df.drop('stock_id', axis=1)
.
You could also use column names with .ix[]
or .loc[]
if you prefer. Has been asked & answered here before. See relevant docs.
Upvotes: 10