import pandas as pd
d = {'x':100,'y':200,'z':300}
s1 =pd.Series(d)
print(s1.values) #dic转化为series
----------------------------------------------
[100 200 300]
import pandas as pd L1= [100,200,300] L2= ['x','y','z'] s1= pd.Series(L1,index= L2) print(s1) ---------------------------------------------- x 100 y 200 z 300 dtype: int64
import pandas as pd s1 = pd.Series([1,2,3],index = [1,2,3],name = 'A') s2 = pd.Series([10,20,30],index = [1,2,3],name = 'B') s3 = pd.Series([100,200,300],index = [1,2,3],name = 'C') df = pd.DataFrame({s1.name:s1,s2.name:s2,s3.name:s3}) print(df) ------------------------------------------------------------------ A B C 1 1 10 100 2 2 20 200 3 3 30 300
import pandas as pd s1 = pd.Series([1,2,3],index = [1,2,3],name = 'A') s2 = pd.Series([10,20,30],index = [1,2,3],name = 'B') s3 = pd.Series([100,200,300],index = [1,2,3],name = 'C') df = pd.DataFrame([s1,s2,s3]) print(df) -------------------------------------------- 1 2 3 A 1 2 3 B 10 20 30 C 100 200 300
import pandas as pd s1 = pd.Series([1,2,3],index = [1,2,3],name = 'A') s2 = pd.Series([10,20,30],index = [1,2,3],name = 'B') s3 = pd.Series([100,200,300],index = [2,3,4],name = 'C') df = pd.DataFrame({s1.name:s1,s2.name:s2,s3.name:s3}) print(df) ------------------------------------------- A B C 1 1.0 10.0 NaN 2 2.0 20.0 100.0 3 3.0 30.0 200.0 4 NaN NaN 300.0