df=pd.DataFrame(columns=['A','B','C'],index=[0,1,2])
结果:
A B C
0 NaN NaN NaN
1 NaN NaN NaN
2 NaN NaN NaN
df=pd.DataFrame(data=[['Apple',5],
['Banana',10],
['Cherry',8],
['Dates',3],
['Eggfruit',7]],
columns = ['Fruits','Quantity'],
index=[1,2,3,4,5])
结果:
Fruits Quantity
1 Apple 5
2 Banana 10
3 Cherry 8
4 Dates 3
5 Eggfruit 7
fruits_list=['Apple','Banana','Cherry','Dates','Eggfruits']
df=pd.DataFrame(fruits_list,
columns = ['Fruits'],
index=['a','b','c','d','e'])
结果:
Fruits
a Apple
b Banana
c Cherry
d Dates
e Eggfruits
fruits_dict = { 'Fruits':['Apple','Banana','Cherry','Dates','Eggfruit'],
'Quantity': [5, 10, 8, 3, 7],
'Color': ['Red', 'Yellow', 'Red', 'Brown', 'Yellow']}
df=pd.DataFrame(fruits_dict)
结果:
Fruits Quantity Color
0 Apple 5 Red
1 Banana 10 Yellow
2 Cherry 8 Red
3 Dates 3 Brown
4 Eggfruit 7 Yellow
fruits = pd.read_csv('fruits.csv')