![](https://csdnimg.cn/release/download_crawler_static/85079151/bg1.jpg)
In[]:
In[]:
In[]:
In[]:
import pandas as pd # 导入pandas库
# 根据列表创建Series类对象
ser_obj = pd.Series(['Python', 'Java', 'PHP'])
ser_obj
# 导入pandas库
import pandas as pd
# 创建Series类对象,同时为该对象指定索引
ser_obj = pd.Series(['Python', 'Java', 'PHP'],index = ['one', 'two', 'three'])
ser_obj
data = {'one': 'Python', 'two': 'Java', 'three': 'PHP'}
ser_obj2 = pd.Series(data) # 根据字典创建Series类对象
ser_obj2
import pandas as pd
from datetime import datetime
# 创建时间戳索引
date_index = pd.to_datetime(['20180820', '20180828', '20180908'])
print(date_index)
# 创建Series类对象,指定索引为时间戳索引
date_ser = pd.Series([11, 22, 33], index=date_index)
print(date_ser)
import numpy as np
import pandas as pd
# 创建二维数组
demo_arr = np.array([['a', 'b', 'c'], ['d', 'e', 'f']])
df_obj = pd.DataFrame(demo_arr) # 根据二维数组创建DataFrame类对象
df_obj
# 创建DataFrame类对象,同时指定行索引与列索引
df_obj = pd.DataFrame(demo_arr, index = ['row_01','row_02'],
columns=['col_01', 'col_02', 'col_03'])
df_obj