我的问题是,如果我使用两个函数,则此代码不接受两个输入参数。
我也尝试从第二个函数中插入和删除click命令和click选项,但是我总是得到主应用程序正在询问其他参数(需要给出2)或代码未执行的信息第二个功能。 (“ add_new_column”)
我在做什么错了?
import pandas as pd
@click.command()
@click.option('--infile', prompt='Your input TSV filename', help='Write your tab separated value filename.')
@click.option('--out', prompt='Your output CSV filename', help='Write your new comma separated value filename.')
def convert_tsv_to_csv(infile, out):
"""Converting a Tab Separated Value into a Comma Separated Value for given files in cli arguments"""
df = pd.read_csv(infile, delimiter='\t')
df.to_csv(out, sep=',')
# @click.command()
# @click.option('--out', prompt='Your output CSV filename', help='Write your new comma separated value filename.')
# def add_new_column(out):
# """Adding a new column named "price_edited" """
# df = pd.read_csv(out, delimiter=',')
# # this line creates a new cloned column from price column, which is a Pandas series.
# # we then add the series to the dataframe, which holds our parsed CSV file
# df['price_edited'] = df['price']
# # save the dataframe to CSV
# df.to_csv(out, sep=',')
if __name__ == '__main__':
convert_tsv_to_csv()
#add_new_column()```
第二次尝试:
import click
import pandas as pd
@click.command()
@click.option('--infile', prompt='Your input TSV filename', help='Write your tab separated value filename.')
@click.option('--out', prompt='Your output CSV filename', help='Write your new comma separated value filename.')
def convert_tsv_to_csv(infile, out):
"""Converting a Tab Separated Value into a Comma Separated Value for given files in cli arguments"""
df = pd.read_csv(infile, delimiter='\t')
df.to_csv(out, sep=',')
def add_new_column():
"""Adding a new column named "price_edited" """
df = pd.read_csv(out, delimiter=',')
# this line creates a new cloned column from price column, which is a Pandas series.
# we then add the series to the dataframe, which holds our parsed CSV file
df['price_edited'] = df['price']
# save the dataframe to CSV
df.to_csv(out, sep=',')
if __name__ == '__main__':
convert_tsv_to_csv()
add_new_column()