我正在使用单击库来从一个文件夹调用函数并读取文件,然后写入文件。
import sys
import numpy as np
import pandas as pd
import click
def count_unique_port(df: pd.DataFrame) -> pd.DataFrame:
df = df.dropna()
df = df.groupby(['A1', 'A2'], as_index=False).size()
return port
@click.command(help="Pandas count")
@click.option("-i", "--input", "infile", type=click.File(), default=sys.stdin, help="Input file name")
@click.option("-o", "--output", "outfile", type=click.File("w"), default=sys.stdout, help="Output file name")
def main(infile, outfile):
df = pd.read_csv(infile)
temp = count_unique_port(df)
print(temp)
temp.to_excel(outfile, index=False)
if __name__ == "__main__":
main()
我偶然发现的问题是当我调用 python 脚本时
python path1/read_data.py ./path/data/f1.csv ./path/data/f2.xlsx
它不会将 pandas 数据帧写入文件夹路径。我做错了什么?欢迎任何帮助。