初学python,主要是记录自己的学习经历,也方便日后查找使用。
欢迎在评论区留下你的问题,我们一起探讨,一起成长
第1部分:使用python读取文档类
1.1 使用python读取excel文档
import pandas as pd
excel_file = '/文件路径/example.xlsx' # 要读取的excel文件位置
sheet_name = 'Sheet1' # 要读取的excel中的sheet名
df = pd.read_excel(excel_file, sheet_name = sheet_name)
print(df)
1.2 使用python读取csv文档
import pandas as pd
df = pd.read_csv('/文件路径/example.csv') # 要读取的csv文件位置
print(df)
1.3 使用python读取txt文档并将其转化成DataFrame
import pandas as pd
import json
dict_list = []
with open('/Users/Desktop/test.txt', 'r', encoding='utf-8') as file:
for line in file:
try:
dict_data = json.loads(