0
import pandas as pd
import numpy as np
df = pd.DataFrame({'Number':[np.linspace(0,10,11,dtype=int)],'Year':[np.linspace(2000,2010,11,dtype=int)],'Person':[np.linspace(10,20,11,dtype=int)],'Age':[np.linspace(30,40,11,dtype=int)]})
df
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • If you are looking for integer range, just use `arange`... – Quang Hoang May 10 '21 at 18:35
  • is this a question about construction of the dataframe or using an existing dataframe? – anky May 10 '21 at 18:40
  • 1
    the question is about the construction of the dataframe - @anky – Nishant May 10 '21 at 18:47
  • remove the bracket around linspace: `df = pd.DataFrame({'Number':np.linspace(0,10,11,dtype=int),'Year':np.linspace(2000,2010,11,dtype=int),'Person':np.linspace(10,20,11,dtype=int),'Age':np.linspace(30,40,11,dtype=int)})` – dallonsi May 11 '21 at 09:10

1 Answers1

2

Remove [ ] around your values:

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "Number": np.linspace(0, 10, 11, dtype=int),
        "Year": np.linspace(2000, 2010, 11, dtype=int),
        "Person": np.linspace(10, 20, 11, dtype=int),
        "Age": np.linspace(30, 40, 11, dtype=int),
    }
)
print(df)

Prints:

    Number  Year  Person  Age
0        0  2000      10   30
1        1  2001      11   31
2        2  2002      12   32
3        3  2003      13   33
4        4  2004      14   34
5        5  2005      15   35
6        6  2006      16   36
7        7  2007      17   37
8        8  2008      18   38
9        9  2009      19   39
10      10  2010      20   40

EDIT: As stated in comments, you can use range() or np.arange as well...

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91