0 1 2 Ticket Open Time 3 5302684589 2020.06.17 01:32:13 ... 4 5302717457 2020.06.17 03:11:57 5 NaN 0 6 Closed P/L: Closed P/L: 7 Ticket Open Time 8 5302718245 2020.06.17 03:12:14 ... I have a database which I have loaded as dataframe by using pandas, I only need the first part data, namely for this example the rows from no.2 to no.4: we can use df.iloc[2:4] which is easy; \nHowever, I have many dataframe that the first part data is not from #2 to #4. \nLucikly, for all dataframe there is one line which is NaN in the first column, for this example, no.5 is NaN in the begining, so I want to identify which row is NaN and then I can know the index of the NaN rows that I can quickly select the first part data I want. \nmy question is how can I select the data I want by using the NaN row, others may also have this problem, so I post it here
3 Réponses :
Cela devrait vous donner le premier index de la ligne où toutes les entrées sont Vous pouvez maintenant faire le nan code> p>
df [df.isnull (). Tout (axe = 1)]. Index [0] code> P>
df.loc [0: df [df.isnull (). Tous (Axis = 1)]. Index [0],:] code> P> P>
Si vous voulez un Dataframe de lignes non nan, vous pouvez faire un df.dropna () code>. Voici la documentation de Pandas officielle au cas où vous voudriez déposer ou sage sur la colonne.
https://pandas.pydata.org/ Pandas-Docs / Stable / Référence / API / Pandas.Dataframe.dropna.html P>
df [df.iloc [:, 0] .isnull ()]. Index [0] Peut résoudre ce problème, sur la base de la réponse de XXavier, tout le crédit vient à lui, merci beaucoup P>
Est-ce que cela répond à votre question? Python Pandas Trouver toutes les lignes où toutes les valeurs sont Nan a>