0

## python 檔案計算問題

1,王小明,410612123,30
2,張小偉,410611715,30
3,陳小潔,610727331,40

### 4 個回答

1

iT邦高手 1 級 ‧ 2022-01-08 14:42:24

``````txt = '''1,王小明,410612123,30
2,張小偉,410611715,30
3,陳小潔,610727331,40'''
x10 = lambda x: x*10
for i in txt.split("\n"):
print(f"{i}, {(140 + x10(int(i[6]))) * (x10(int(i[-2])) + int(i[-1]))}")
``````

shenglee iT邦新手 5 級 ‧ 2022-01-13 15:08:09 檢舉

print(f"{i}, {(140 + x10(int(i[6]))) * (x10(int(i[-2])) + int(i[-1]))}")

shenglee 忘加括號了，謝指教

1

iT邦大神 1 級 ‧ 2022-01-08 16:24:18

0
I code so I am
iT邦高手 1 級 ‧ 2022-01-09 14:45:10

data.csv 內容為：

1,王小明,410612123,30
2,張小偉,410611715,30
3,陳小潔,610727331,40

``````import pandas as pd

def func(row):
return row['本月時數'] * 180 if str(row['學號']).startswith('4') else row['本月時數'] * 200

df=pd.read_csv('data.csv')
df['小計'] = df.apply(func, axis=1)
print(df)
``````
0

iT邦大師 1 級 ‧ 2022-01-10 22:09:35

``````create extension file_fdw;

create server ithelp
foreign data wrapper file_fdw;

create foreign table ithelp0110 (
id int
, iname text
, ino text
, whr int
) server ithelp
options (filename '/tmp/ithelp.txt', format 'csv');

select *
, case left(ino,1)::int
when 4 then 180 * whr
when 6 then 200 * whr
else 0
end
from ithelp0110;
``````