Write a Pandas program to convert given series into a dataframe with its index as another column on the dataframe

  • برمجة بايثون

Write a Pandas program to convert given series into a dataframe with its index as another column on the dataframe

الأجوبة

import numpy as np
import pandas as pd
char_list = list('ABCDEFGHIJKLMNOP')
num_arra = np.arange(8)
num_dict = dict(zip(char_list, num_arra))
num_ser = pd.Series(num_dict)
df = num_ser.to_frame().reset_index()
print(df.head())

Sample Output:

  index  0
0     A  0
1     B  1
2     C  2
3     D  3
4     E  4
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...