从.csv文件读数据
import pandas as pd
train_df = pd.read_csv("datasets/train01.csv")
val_df = pd.read_csv("datasets/val01.csv")
test_df = pd.read_csv("datasets/test01.csv")
print("Train Data:")
print(train_df.head())
print("\nValidation Data:")
print(val_df.head())
print("\nTest Data:")
print(test_df.head())
把数据写到.csv文件
output_df = pd.DataFrame({
'Column1': [1, 2, 3],
'Column2': ['A', 'B', 'C']
})
output_df.to_csv("output_file.csv", index=False)
train_df[["label", "cutword"]].to_csv("datasets/train01.csv", index=False)
val_df[["label", "cutword"]].to_csv("datasets/val01.csv", index=False)
test_df[["label", "cutword"]].to_csv("datasets/test01.csv", index=False)