def add_quotes_comma(element): return f'"{element}",' list(yuanshi_df1['投保单号·'].apply(add_quotes_comma)) 输出的结果为:['"TDAA202312000000492780",', '"TDAA202312000000498187",'] 列表中的每个元素都默认加上‘’,请问如何去除,使得输出结果为:["TDAA202312000000492780",'"TDAA202312000000498187",]
时间: 2023-08-07 22:10:50 浏览: 94
您可以修改`add_quotes_comma`函数,使用`strip`方法去除字符串两端的引号。修改后的代码如下:
```python
def add_quotes_comma(element):
return f'{element.strip("\"")},'
result = list(yuanshi_df1['投保单号·'].apply(add_quotes_comma))
```
这样输出结果就会变为:`["TDAA202312000000492780", "TDAA202312000000498187",]`,引号已经被去除了。
相关问题
df = pd.read_csv('stock_comments_analyzed.csv', parse_dates=['created_time']) grouped = df['polarity'].groupby(df.created_time.dt.date) def BI_Simple_func(row): pos = row[row == 1].count() neg = row[row == 0].count() return (pos-neg)/(pos+neg) BI_Simple_index = grouped.apply(BI_Simple_func) def BI_func(row): pos = row[row == 1].count() neg = row[row == 0].count() bi = np.log(1.0 * (1+pos) / (1+neg)) return bi BI_index = grouped.apply(BI_func) sentiment_idx = pd.concat([BI_index.rename('BI'), BI_Simple_index.rename('BI_Simple')], axis=1) quotes = pd.read_csv('./data/sh000001.csv', parse_dates=['date']) quotes.set_index('date', inplace=True) sentiment_idx.index = pd.to_datetime(sentiment_idx.index) merged = pd.merge(sentiment_idx, quotes, how='left', left_index=True, right_index=True) merged.fillna(method='ffill', inplace=True) merged['BI_MA'] = merged['BI'].rolling(window=10, center=False).mean() merged['BI_Simple_MA'] = merged['BI_Simple'].rolling(window=10, center=False).mean() merged.to_csv('merged_sentiment_idx.csv')
这段代码是关于股票情绪指数的计算和处理,包括读取股票评论数据并按日期分组,定义了两个函数用于计算简单的情绪指数和 BI 指数,然后将这些指数与股票行情数据进行合并并计算移动平均数,最后将结果保存到 csv 文件中。其中,BI 指数是一种用于衡量市场情绪的指标,通过计算买方和卖方之间的力量平衡来反映市场的情绪状态。
/opt/scripts/shell/check_pod_process_num.sh: line 17: syntax error: unexpected end of file
This error message indicates that there is a syntax error in the shell script "check_pod_process_num.sh" and specifically at line 17. The error is caused by an unexpected end of file, which means that the script ended prematurely without completing a required section of code.
To resolve this error, you should carefully review the script from the beginning to line 17 and check for any missing or incomplete statements. You should also ensure that all opening brackets have a corresponding closing bracket, and all quotes and parentheses are correctly matched. Once you have identified and fixed the syntax error, you can save the script and run it again to verify that it runs without errors.
阅读全文