0

I am basically trying to write my results in csv file. However, the amount of row numbers in each column is different. when it is written, values stop at the minimum row number, however, I have still values in the other column but don't write them. For example, HYG_FT01 produces 100 values and HYG_PU12_PW produces 140 values after the calculation. When it comes to writing in CSV file, I see 100 values in each column for both. I used df.append function, and got same problem. Also changed ffill to bfill but, did not work.

Here is my code:

features = ['HYG_FT01', 'HYG_PU12_PW_PV']
df = pd.read_csv('HYG_2021_08.csv', usecols=features, sep=';', encoding='ISO-8859-1')

for features in df:
    new_df = df[[features]].quantile(q=.99, axis=0, numeric_only=True)
    df.drop(df[df[features] > new_df.iloc[0]].index, inplace=True)
    print(df[features].describe())
    df.replace([features], method='ffill').to_csv('trials.csv', index=False)

Tom Ron
  • 5,906
  • 3
  • 22
  • 38
bazinga
  • 41
  • 5
  • Does this answer your question? [add columns different length pandas](https://stackoverflow.com/questions/27126511/add-columns-different-length-pandas) – Mahery Ranaivoson Oct 20 '21 at 07:14
  • Can't replicate. Could you please add a [mre](https://stackoverflow.com/help/minimal-reproducible-example) (also look [here](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) that replicates your problem s.t. other can see it too? Also, please add more information (os, versions, etc.). – Timus Oct 20 '21 at 07:20

0 Answers0