Python Forum
Knowing the index of a data frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Knowing the index of a data frame
#1
Good morning, this is my first message in the forum so Hi Big Grin .
I have a doubt and I don't know how to proceed, I'm trying to compare two columns in two different data frames.
import pandas as pd
import numpy as np
from sklearn import linear_model
from sklearn import model_selection
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
import seaborn as sb


df = pd.read_csv(r"Prueba1CSV.csv", sep=";")
df1= pd.read_csv(r"Prueba2CSV.csv", sep=";")


    def is_in_column(data, values):
        if data in values:
            return True
        else:
            return False
        

df['Present_in_other'] = df[Cabeza].apply(is_in_column, values=df1[Cabeza2].tolist())
df3=df[df['Present_in_other']==False]
The problem is that now what I'm returning in "is_in_column" is True and what I want to return is the index in which it founds the coincidence.

Maybe it's very easy but I don't know how to do it.

Thanks,
Iván
Reply
#2
Once you read the source data CSV files you can create indexes, so you can see the index in resultant tables.

df = df.rename_axis('df_index').reset_index()
df1 = df1.rename_axis('df2_index').reset_index()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 539 Dec-24-2023, 10:00 AM
Last Post: perfringo
  how do you style data frame that has empty rows. gsaray101 0 500 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  googletrans library to translate text language for using data frame is not running gcozba2023 0 1,164 Mar-06-2023, 09:50 AM
Last Post: gcozba2023
  Load multiple Jason data in one Data Frame vijays3 6 1,500 Aug-12-2022, 05:17 PM
Last Post: vijays3
  conditionals based on data frame mbrown009 1 873 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Merging two Data Frame on a special case piku9290dgp 0 1,069 Mar-02-2022, 10:43 AM
Last Post: piku9290dgp
  Save data frame to .csv df.to.csv() mcva 1 1,497 Feb-03-2022, 07:05 PM
Last Post: mcva
  Move a particular row in pandas data frame to last row klllmmm 0 3,647 Dec-27-2021, 09:11 AM
Last Post: klllmmm
  Iterating Through Data Frame Rows JoeDainton123 2 2,866 Aug-09-2021, 07:01 AM
Last Post: Pedroski55
  Filtering a data frame according to number of occurences of an observation Menthix 1 1,851 May-31-2021, 10:50 PM
Last Post: supuflounder

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020