python dataframe列名_Python 3.x-使用来自另一个datafram的列名创建dataframe

Dataframe df1包含具有列名的字段“Column headers”。我想创建另一个数据帧df2,它只包含df1的“column headers”列中的列标题。print(df1['Column header'])

>>

0 % Female

1 % Below poverty line

2 % Rural population

3 Decadal Population Growth (in %)

4 Availability of Drinking Water Source Within P...

5 Concrete Roofs (in %)

6 Houses With Electricity (in %)

7 Houses With Televisions (in %)

8 With Computer/Laptop (in %)

9 Houses With Phones (Telephone + Mobile) (in %)

10 Houses With 2 wheelers (in %)

11 Houses With cars (in %)

12 Households With Banking Services (in %)

13 Literacy Rate (in %)

14 Literacy Rate (Rural) (in %)

15 Literacy Rate (Urban) (in %)

16 Decadal Difference In Literacy Rate

17 Student: Teacher Ratio - All Schools

18 Student: Teacher Ratio - Primary

19 Student: Teacher Ratio - Upper Primary

20 Under-five Mortality Rate (Per 1000 live Births)

21 No of Dispensaries per 1,00,000 population

22 No of Doctors per 1,00,000 population

23 Total patients registered for tuberculosis tre...

24 Sex Ratio (Females Per 1000 Males)

25 Agri GSDP (%)

26 Industry GSDP (%)

27 Service GSDP (%)

28 Unemployment Rate (2011-12)

29 Rural Unemployment Rate (2011-12)

30 Urban Unemployment Rate (2011-12)

31 Per Capita Public Expenditure (in Rs)

32 Per Capita Private Expenditure (in Rs)

33 Infant Mortality Rate (IMR)

34 Maternal Mortality Rate

35 Coverage Of National Highways (Total in km)

36 Coverage Of State Highways (Total in km)

37 Coverage Of Rural Roads (Total in km)

38 Coverage Of Urban Roads (Total in km)

39 Railway Coverage (Total in km)

40 Tele-Density [Total Connections / Total Popul...

Name: Column headers, dtype: object

我想创建包含40列的数据帧df2,如前所述。此数据框中的行将由另一个函数填充。

我试图创建df2如下-df2 = pd.DataFrame() #Creating an empty dataframe

df2.columns = df1['Column header']

>>

ValueError: Length mismatch: Expected axis has 0 elements, new values have 41 elements

是否可以在Pandas中创建一个空白数据框,然后指定列名?

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值