python从excel中读取数据 写入word_在python3中从excel到word的数据传输

只是为了展示您使用pandas的示例性功能:import pandas as pd

df = pd.read_csv('whereverfilemayroam/filename')

Participant ID Breakfasts Lunches/dinners Snacks

0 1111 Full english Risotto Granola

1 1111 Full english Risotto Granola

2 1111 Full english Risotto Granola

3 1111 Full english Risotto Granola

4 1111 Full english Risotto Granola

5 1111 Full english Risotto Granola

6 1111 Full english Risotto Granola

7 1111 None Risotto Granola

8 1111 None Risotto Granola

9 1111 None Risotto Granola

10 1111 None Risotto Granola

11 1111 None Risotto Granola

12 1111 None Risotto Granola

13 1111 None Risotto Granola

14 2222 Avocado toast Bean chilli Apple

15 2222 Avocado toast Bean chilli Apple

16 2222 Avocado toast Bean chilli Apple

17 2222 Avocado toast Bean chilli Apple

18 2222 Avocado toast Bean chilli Apple

19 2222 Avocado toast Bean chilli Apple

20 2222 Avocado toast Bean chilli Apple

21 2222 None Bean chilli Apple

22 2222 None Bean chilli Apple

23 2222 None Bean chilli Apple

24 2222 None Bean chilli Apple

25 2222 None Bean chilli Apple

26 2222 None Bean chilli Apple

27 2222 None Bean chilli Apple

这是pandas数据帧中的文件,pandas中的标准容器,如果您愿意的话。现在你可以用它做大量的统计数据。。。只需在docs中挖掘一点

示例:

^{pr2}$

当然,您可以按参与者ID分开:oneoneoneone = df[df['Participant ID'] == 1111]

oneoneoneone

Participant ID Breakfasts Lunches/dinners Snacks

0 1111 Full english Risotto Granola

1 1111 Full english Risotto Granola

2 1111 Full english Risotto Granola

3 1111 Full english Risotto Granola

4 1111 Full english Risotto Granola

5 1111 Full english Risotto Granola

6 1111 Full english Risotto Granola

7 1111 None Risotto Granola

8 1111 None Risotto Granola

9 1111 None Risotto Granola

10 1111 None Risotto Granola

11 1111 None Risotto Granola

12 1111 None Risotto Granola

13 1111 None Risotto Granola

oneoneoneone.to_csv('target_file')

也许也是twotwotwotwo.to_csv('another_target_file')

也可以迭代组,然后对每个组应用相同的操作。

e、 g.:for name, group in df.groupby('Participant ID'):

print(name)

print(group.groupby('Breakfasts').Breakfasts.count().to_string())

print(group.groupby('Lunches/dinners')['Lunches/dinners'].count().to_string())

print(group.groupby('Snacks').Snacks.count().to_string(), '\n')

退货:1111

Breakfasts

Full english 7

Lunches/dinners

Risotto 14

Snacks

Granola 14

2222

Breakfasts

Avocado toast 7

Lunches/dinners

Bean chilli 14

Snacks

Apple 14

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值