简体   繁体   English

Pandas dataframe。 错误的系列飞线

[英]Pandas dataframe. Wrong series fly in the line

在此处输入图像描述 I want to have 81 rows x 1 columns.我想要 81 行 x 1 列。 How to correct this distortion?如何纠正这种失真?

Use fillna .使用fillna Basically, use the values in the second column to fill holes in the first column:基本上,使用第二列中的值来填充第一列中的孔:

df['first_column'].fillna(df['second_column'])

For example, if you have DataFrame df :例如,如果您有 DataFrame df

     a      b
0  1.0    NaN
1  2.0    NaN
2  NaN  100.0

then然后

df['a'] =  df['a'].fillna(df['b'])
df = df.drop(columns=['b'])

Output: Output:

       a
0    1.0
1    2.0
2  100.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM