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

4
  • Use df=df.loc[(df['column 1'] != "abc") & (df['column 2'] == "def" )] Commented Mar 26, 2020 at 7: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 Commented Mar 26, 2020 at 7:43
  • Welcome to StackOverflow. Please take the time to read this post on how to provide a great pandas example as well as how to provide a minimal, complete, and verifiable example and revise your question accordingly. These tips on how to ask a good question may also be useful. Commented Mar 26, 2020 at 7: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 ... Commented Mar 26, 2020 at 8:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.