快速创建一个pandas Data_Frame ,方便测试

import numpy as np
import pandas as pd
data = np.random.randn(6, 4)
df = pd.DataFrame(data,columns=['a','b','c','d'])

print(df)    
          a         b         c         d
0  0.401976  0.735167  1.039404 -0.649782
1 -0.860005  0.437051 -0.575513 -0.333293
2  0.163809 -0.297073  0.964990 -0.599854
3  1.869033 -0.856488  0.687006  2.035814
4  1.819477  0.243325  1.306515  1.159489
5 -1.594146  0.330584 -0.862533  0.937375

第二个example:

# Make example dataframe
df = pd.DataFrame([(1, 'Germany'),
                   (2, 'France'),
                   (3, 'Indonesia'),
                   (4, 'France'),
                   (5, 'France'),
                   (6, 'Germany'),
                   (7, 'UK'),
                   ],
                  columns=['groupid', 'country'],
                  index=['a', 'b', 'c', 'd', 'e', 'f', 'g'])

第三个:

import numpy as np
import pandas as pd
df = pd.DataFrame([['Snow','M',22],['Tyrion','M',32],['Sansa','F',18],['Arya','F',14]], columns=['name','gender','age'])

猜你喜欢

转载自blog.csdn.net/Dawei_01/article/details/80484201