import pandas as pd
import warnings
warnings.filterwarnings("ignore")
scientists = pd.read_csv('./data/scientists.csv')
names = scientists['Name']
print(names)
import os
if not os.path.exists('./output/scientists_names_series.csv'):
names.to_csv('./output/scientists_names_series.csv')
if not os.path.exists('./output/scientists_names_series1.csv'):
#分隔符变成星号
names.to_csv('./output/scientists_names_series1.csv',sep='*')
if not os.path.exists('./output/scientists_names_series2.csv'):
#序号去掉,就是把行号去掉
names.to_csv('./output/scientists_names_series2.csv',index=False)
if not os.path.exists('./output/scientists_df1.csv'):
scientists.to_csv('./output/scientists_df1.csv')
if not os.path.exists('./output/scientists_df2.csv'):
scientists.to_csv('./output/scientists_df2.csv',index=False)
import pandas as pd
#s1 = pd.Series([43,56])
#print(s1)
scientists = pd.read_csv('./data/scientists.csv')
names = scientists['Name']
print(names)
import os
if not os.path.exists('./output/scientists_names_series.pickle'):
names.to_pickle('./output/scientists_names_series.pickle')
if not os.path.exists('./output/scientists_df.pickle'):
scientists.to_pickle('./output/scientists_df.pickle')
#读取pickle文件
scientists_name_from_pickle = pd.read_pickle('./output/scientists_names_series.pickle')
print(scientists_name_from_pickle)
scientists_name_from_pickle = pd.read_pickle('./output/scientists_df.pickle')
print(scientists_name_from_pickle)
#读写Excel 格式的Series和DataFrame文件
import pandas as pd
scientists = pd.read_csv('./data/scientists.csv')
names = scientists['Name']
#print(names)
names.to_excel('./output/scientists_names_series.xls')
#可以吧Series转成DataFrame
names_df = names.to_frame()
names_df.to_excel('./output/scientists_names_series1.xls')
#就是吧底下的sheet 改个名字
scientists.to_excel('./output/scientists_df.xlsx',sheet_name='scientists',index=False)
#读取excel文件
import xlrd
# 打开workbook 获取sheet
data = xlrd.open_workbook('./output/scientists_df.xlsx')
sheet = data.sheet_by_name('scientists')
sheet = data.sheet_by_index(0)
#第一行数据
print(sheet.row_values(1))
#第一个列
print(sheet.col_values(1))
print('行数','=',sheet.nrows)
print('列数','=',sheet.ncols)
print(sheet.cell(0,0).value)
#第二行,第三个 都是从0开始的
print(sheet.cell(2,3).value)
print(data.sheet_names())
print(sheet.name)
#获取一整行数据
print(sheet.row_values(3))
#获取一整列的数据
print(sheet.col_values(2))