我想锁定数据框中的几列以仅允许数字(无字符)。
我尝试了下面的代码,当我手动输入值时(它不允许我输入字符),它工作得很好,但是当我尝试复制和粘贴字符时,它并不能阻止我这样做
import pandas as pd
df = pd.DataFrame({'Data1': [10, 20, 30, 20, 15, 30, 45],
'Data2': [11, 21, 31, 21, 15, 31, 45]})
writer = pd.ExcelWriter('pandas_filter.xlsx', engine='xlsxwriter', )
df.to_excel(writer, sheet_name='Sheet1', index=False)
workbook = writer.book
worksheet = writer.sheets['Sheet1']
worksheet.data_validation('A2:B8', {'validate': 'custom',
'value': '=ISNUMBER(A2:A8)'})
writer.save()