0
#importing libraries
import numpy as nm
import pandas as pd
import matplotlib.pyplot as plt
data_set_X = pd.read_csv('train.csv')

df=pd.DataFrame(data_set_X)
df2=pd.DataFrame()

for i in range(480,len(df),1440):
 
 for j in range(i, i+361, 10):
       df2.append((df.loc[j]))
       
print(df2)

after running the code it's printing empty DataFrame means data is not added so what correction should I make in my code in order to append data from another DataFrame? I can't use multiple lists since my training dataset has many columns

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • 1
    Please post your code as text inline and not as a screenshot. – petezurich Oct 27 '21 at 13:03
  • append will return a new dataframe. You need to assign back to df2.... df2 = df2.append(....) – EBDS Oct 27 '21 at 13:16
  • "DataFrame.append is not an in-place operation You need to assign the result back." [src](https://stackoverflow.com/a/53924703/15497888) but also see [NEVER grow a DataFrame!](https://stackoverflow.com/a/56746204/15497888) for some more options – Henry Ecker Oct 27 '21 at 13:26

2 Answers2

0

Use this, it'll be faster

pd.concat([df.loc[i:i+361:10] for i in range(480, len(df), 1440)]) 
Riley
  • 2,153
  • 1
  • 6
  • 16
0

You could you use:

df2 = df2.append((df.loc[j]))

Also, to check what is happening, you could print df.loc[j] in the loop.

print(df.loc[j])
df2 = df2.append((df.loc[j]))

This method is the less efficient method. I'll leave it up to you to find the more effcient method: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html

Bende
  • 91
  • 8