我试图在dataframe的末尾追加一个空行,但无法这样做,甚至试图理解pandas如何使用append函数,但仍然没有得到它
代码如下:
import pandas as pd
excel_names = ["ARMANI+EMPORIO+AR0143-book.xlsx"]
excels = [pd.ExcelFile(name) for name in excel_names]
frames = [x.parse(x.sheet_names[0], header=None,index_col=None).dropna(how='all') for x in excels]
for f in frames:
f.append(0, float('NaN'))
f.append(2, float('NaN'))
有两列和随机数行
在for循环中使用“print f”时,我得到以下结果:
0 1
0 Brand Name Emporio Armani
2 Model number AR0143
4 Part Number AR0143
6 Item Shape Rectangular
8 Dial Window Material Type Mineral
10 Display Type Analogue
12 Clasp Type Buckle
14 Case Material Stainless steel
16 Case Diameter 31 millimetres
18 Band Material Leather
20 Band Length Women's Standard
22 Band Colour Black
24 Dial Colour Black
26 Special Features second-hand
28 Movement Quartz
使用pandas.DataFrame.append()添加新的pandas.Series
如果希望指定新行的名称(也称为“索引”),请使用:
如果不希望命名新行,请使用:
其中
df
是pandas.DataFrame您可以通过如下方式向数据帧追加一个系列来添加它。我假设为空白,您的意思是要添加仅包含“Nan”的行。 可以首先使用Nan创建序列对象。确保在-Index参数中定义“Series”对象时指定列。 您可以将其附加到DF。希望有帮助
您可以添加一个新系列,同时将其命名。该名称将是新行的索引,所有值将自动为NaN
相关问题 更多 >
编程相关推荐