How do you import and export data in Splite?
To import and export data, you need to use the read_csv() and to_csv() methods in the pandas library.
Firstly, you need to install the Pandas library. You can install it using the following command:
pip install pandas
Import data:
import pandas as pd
# 导入CSV文件
data = pd.read_csv('data.csv')
The code above imports data from a CSV file named “data.csv” and stores it in a DataFrame object called data.
Export data.
import pandas as pd
# 创建一个示例数据
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'London', 'Tokyo']}
df = pd.DataFrame(data)
# 导出为CSV文件
df.to_csv('data.csv', index=False)
The above code exports the data from the DataFrame object df to a CSV file named “data.csv”. Setting index=False prevents the index column from being exported.