OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Filtered dataframe not correct

  • Thread starter Thread starter Lagos
  • Start date Start date
L

Lagos

Guest
I try to filter a dataframe using the following expression: I am seeking the times "col" changes to "val":

filtered_df = df[(df[col]== val) & (df.shift(1)[col] != df[col])]

df is a dataframe that is generated by a function: df= create_df(data)

The filtered_df is empty even though there condition is verified at least one time in my data.

When I try to export my df to a csv file:

data = pd.to_csv("out") then

Apply the above filter to data, it works, I get a non empty dataframe.

I don't know how to explain this , "df" and "data" are meant to be the same.

Any help please? Thanks9
<p>I try to filter a dataframe using the following expression: I am seeking the times "col" changes to "val":</p>
<p><code>filtered_df = df[(df[col]== val) & (df.shift(1)[col] != df[col])]</code></p>
<p>df is a dataframe that is generated by a function: <code>df= create_df(data)</code></p>
<p>The filtered_df is empty even though there condition is verified at least one time in my data.</p>
<p>When I try to export my df to a csv file:</p>
<p><code>data = pd.to_csv("out")</code> then</p>
<p>Apply the above filter to data, it works, I get a non empty dataframe.</p>
<p>I don't know how to explain this , "df" and "data" are meant to be the same.</p>
<p>Any help please? Thanks9</p>
 
Top