DataFrame with one column 0 to 100

Question:

I need a DataFrame of one column [‘Week’] that has all values from 0 to 100 inclusive.

I need it as a Dataframe so I can perform a pd.merge

So far I have tried creating an empty DataFrame, creating a series of 0-100 and then attempting to append this series to the DataFrame as a column.

alert_count_list = pd.DataFrame()
week_list= pd.Series(range(0,101))
alert_count_list['week'] = alert_count_list.append(week_list)
Asked By: TisButaScratch

||

Answers:

Try this:

df = pd.DataFrame(columns=["week"])
df.loc[:,"week"] = np.arange(101) 
alert_count_list = pd.DataFrame(np.zeros(101), columns=['week'])

or

alert_count_list = pd.DataFrame({'week':range(101)})
Answered By: amalik2205

You can try:

week_vals = []
for i in range(0, 101):
    week_vals.append(i)

df = pd.Dataframe(columns = ['week'])
df['week'] = week_vals
Answered By: Joe
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.