create panda dataframe and append values in for loop
<p>I have a list from which I would like to iterate over and create tuples in a pandas dataframe in order to imitate sliding window of size 4. What I am trying to do is:</p>

<pre><code>tuples = pd.DataFrame()
for index, row in expertsDF.iterrows():
      newlst = row['name'] 
      counter = 0
      for x in newlst:
        if counter &lt; len(newlst) - 3:
            tuples['A'] = x
            tuples['B'] =newlst(counter+1)
            tuples['C'] =newlst(counter+2)
            tuples['D'] =newlst(counter+3)
            counter = counter + 1
</code></pre>

<p>the newlst looks like this:</p>

<pre><code>list (var1, var2, var3....)
</code></pre>

<p>and my DataFrame should be like this:</p>

<pre><code>     A       B      C       D
1   var1   var2   var3    var4
2   var2   var3   var4    var5
3   var3   var4   var5    var6
</code></pre>

<p>Is there a way to do that in python?</p>

<p>How about creating the DataFrame from Series objects?</p>

<pre><code>import pandas as pd

data_list = list(map(lambda x: 'var{}'.format(x),range(0,100)))
df = pd.Series(data_list[0:97]).to_frame(name='A')
df['B'] = pd.Series(data_list[1:98])
df['C'] = pd.Series(data_list[2:99])
df['D'] = pd.Series(data_list[3:100])

df.head()

# output
#       A     B     C     D
# 0  var0  var1  var2  var3
# 1  var1  var2  var3  var4
# 2  var2  var3  var4  var5
# 3  var3  var4  var5  var6
# 4  var4  var5  var6  var7
</code></pre>

python list dataframe append