0
df= pd.read_csv("3.csv")
df=df.loc((df['column 1'] != "abc") & df['column 2'] == "def" ) # return a series by using boolean find

assume df will got 10 rows so now df will be maybe selected 5 from orignal df. Then example data maybe

#example value as table format
<> column 1 column 2 column3
0  abc      def       z 
1  abc      def       s  #original maybe 3
2  abc      def       q  #ori 7
3  abc      def       2  #8
4  abc      def       l  #9

Are there any way to maintain the original index value? Because I want to update the orignal dataframe with the selected value. Tried something like df.index but it is the latest index

  • Use `df=df.loc[(df['column 1'] != "abc") & (df['column 2'] == "def" )]` – jezrael Mar 26 '20 at 07:36
  • er.. sorry, the way of getting smaller dataframe from big dataframe i am achieved, but I actually i am asking how to get the original index for example the smaller got 5, i want the 01234 be 03789 – kah lun teoh Mar 26 '20 at 07:43
  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Mar 26 '20 at 07:44
  • ok, thanks for the suggestion on how to give a reproducible answer, it is giving old indices, but because I keep tested with the first column ... – kah lun teoh Mar 26 '20 at 08:01

0 Answers0