Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am working on time series with 3 columns. In those 3 columns, I wanted to copy 2 columns after the last row and the same with the 3rd columns.

To do this I used a for loop and tried to append the data frame but it is not working. There no warning no error. This is the data frame:

    val01_ambient_temperature   val01_ambient_winddir   val01_ambient_windspeed

measure_time            

2019-03-24 07:30:00 12.956060   108.200005  4.166667

2019-03-24 07:40:00 12.999207   103.000000  3.666667

2019-03-24 07:50:00 12.761206   106.500000  4.533333

2019-03-24 08:00:00 12.523205   98.413330   3.916667

2019-03-24 08:10:00 12.285204   97.853333   4.055000

This is the code:

counterTest=0

for column in dataImport_selVar100:

    if counterTest==0: #initialize

        result0=pd.DataFrame(dataImport_selVar100.iloc[:,counterTest])

    else:

        result1=pd.DataFrame(dataImport_selVar100.iloc[:,counterTest])

        result0.append(result1,ignore_index=True,sort=False)

    #print(result[column])

    counterTest +=1

The results i am getting is :

<class 'pandas.core.frame.DataFrame'>

DatetimeIndex: 100 entries, 2019-03-24 07:30:00 to 2019-03-25 00:00:00

Data columns (total 1 columns):

val01_ambient_temperature    100 non-null float64

dtypes: float64(1)

memory usage: 6.6 KB

Expected results are:

<class 'pandas.core.frame.DataFrame'>

DatetimeIndex: 300 entries, 2019-03-24 07:30:00 to 2019-03-25 00:00:00

Data columns (total 3 columns):

val01_ambient_temperature    100 non-null float64

val01_ambient_winddir        100 non-null float64

val01_ambient_windspeed      100 non-null float64

dtypes: float64(2)

memory usage: 7.0 KB

1 Answer

0 votes
by (36.8k points)

result0.append(result1,ignore_index=True,sort=False)

Append will return the new data frame. This won't happen in place. So you need to use:

result0 = result0.append(result1,ignore_index=True,sort=False)

Improve your knowledge in data science from scratch using Data science online courses

Browse Categories

...