[英]Store nth row elements in a list panda dataframe
I am new to python.Could you help on follow I have a dataframe as follows.我是 python 的新手。你能帮忙看看我有一个 dataframe 如下。 a,d,f & g are column names. a,d,f & g 是列名。 dataframe can be named as df1
dataframe可以命名为df1
a d f g
20 30 20 20
0 1 NaN NaN
I need to put second row of the df1 into a list without NaN's
.我需要将 df1 的第二行放入没有NaN's
列表中。 Ideally as follows.理想情况如下。
x=[0,1] x=[0,1]
Check itertuples()检查itertuples()
So you would have something like taht:所以你会有类似的东西:
for row in df1.itertuples():
row[0] #-> that's your index of row. You can do whatever you want with it, as well as with whole row which is a tuple now.
you can also use iloc and dropna() like that:你也可以像这样使用iloc和dropna() :
row_2 = df1.iloc[1].dropna().to_list()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.