随笔分类 -  pandas

摘要:import pandas excel=pandas.read_excel(r'E:\pandas练习\成绩单.xlsx') b=excel.style.bar(color='orange',subset=['test_1','test_2','test_3']) b.to_excel() 阅读全文
posted @ 2020-07-11 11:11 马蹄哒哒 阅读(191) 评论(0) 推荐(0)
摘要:import seaborn import pandas excel=pandas.read_excel(r'E:\pandas练习\成绩单.xlsx') color_map=seaborn.light_palette('green',as_cmap=True) a=excel.style.back 阅读全文
posted @ 2020-07-11 11:02 马蹄哒哒 阅读(158) 评论(0) 推荐(0)
摘要:import pandas excel=pandas.read_excel(r'E:\pandas练习\成绩单.xlsx') def low_score_red(s): color="red" if s<60 else "black" return "color:{}".format(color) 阅读全文
posted @ 2020-07-11 10:53 马蹄哒哒 阅读(206) 评论(0) 推荐(0)
摘要:import pandas a=pandas.DataFrame({'Country': ['China,US', 'Japan,EU', 'UK,Australia', 'Singapore,Netherland'], 'Number': [100, 150, 120, 90], 'Value': 阅读全文
posted @ 2020-06-28 18:24 马蹄哒哒 阅读(342) 评论(0) 推荐(0)
摘要:import pandas a=pandas.read_excel(r'D:\scrapy网络爬虫\nba.xlsx') bins=[0,5000000,max(a['Salary'])] group_by=['底','高'] a['new_col']=pandas.cut(a['Salary'], 阅读全文
posted @ 2020-06-28 14:36 马蹄哒哒 阅读(285) 评论(0) 推荐(0)
摘要:import pandas a=pandas.read_excel() def abc(x): return ','.join(x.values) b=a.groupby(['列名'1])['列名2'].apply(abc) c=b.reset_index() print(c) 阅读全文
posted @ 2020-06-27 22:00 马蹄哒哒 阅读(587) 评论(0) 推荐(0)
摘要:a=['序号',1,2,3,4,5] b=['成本',20,45,12,34,67] import pandas c=pandas.Series(a) d=pandas.Series(b) e=pandas.DataFrame(list(zip(c,d))) print(e) 0 1 0 序号 成本 阅读全文
posted @ 2020-06-26 16:52 马蹄哒哒 阅读(2810) 评论(0) 推荐(0)
摘要:import pandas import numpy def get_circle_area(l,h): r=numpy.sqrt(l**2+h**2)/2 return r**2*numpy.pi excel=pandas.read_excel('长方形.xlsx',index_col='id') 阅读全文
posted @ 2020-06-15 11:36 马蹄哒哒 阅读(654) 评论(0) 推荐(0)
摘要:1 import pymysql 2 import pandas 3 db=pymysql.connect(host='localhost',port=3306,user='root',database='lihao',password='lh19990317') 4 #cursor=db.curs 阅读全文
posted @ 2020-06-15 11:20 马蹄哒哒 阅读(184) 评论(0) 推荐(0)
摘要:import pandas import numpy page1=pandas.read_excel('成绩.xlsx',sheet_name='Sheet1') page2=pandas.read_excel('成绩.xlsx',sheet_name='Sheet2') page1.columns 阅读全文
posted @ 2020-06-15 09:45 马蹄哒哒 阅读(419) 评论(0) 推荐(0)
摘要:import pandas sheet1=pandas.read_excel('成绩.xlsx',sheet_name='Sheet1') sheet2=pandas.read_excel('成绩.xlsx',sheet_name='Sheet2') 连接两张表 students=sheet1.ap 阅读全文
posted @ 2020-06-14 17:57 马蹄哒哒 阅读(328) 评论(0) 推荐(0)
摘要:1 import pandas 2 from matplotlib import pyplot 3 from scipy.stats import linregress 4 sale=pandas.read_excel('销售.xlsx',dtype={'date':str}) 5 6 7 slop 阅读全文
posted @ 2020-06-14 11:24 马蹄哒哒 阅读(380) 评论(0) 推荐(0)
摘要:1 import pandas 2 import numpy 3 csv=pandas.read_csv('salesmen.csv') 4 csv['Month']=pandas.DatetimeIndex(csv['Date']).month 5 6 #透视表制作方法一: 7 #pt=csv.p 阅读全文
posted @ 2020-06-13 13:14 马蹄哒哒 阅读(305) 评论(3) 推荐(0)
摘要:1 import pandas 2 csv=pandas.read_csv('salesmen.csv') 3 tsv=pandas.read_csv('a.tsv',sep='\t') #sep代表制表符的种类 4 txt=pandas.read_csv('b.txt',sep='-') 5 pr 阅读全文
posted @ 2020-06-13 12:28 马蹄哒哒 阅读(360) 评论(0) 推荐(0)
摘要:1 import pandas 2 pandas.options.display.max_columns=20 #显示所有的列名 3 excel=pandas.read_excel('成绩.xlsx',index_col='id') 4 table=excel.transpose() #旋转表 5 阅读全文
posted @ 2020-06-13 11:38 马蹄哒哒 阅读(205) 评论(0) 推荐(0)
摘要:1 import pandas 2 excel=pandas.read_excel('成绩.xlsx',sheet_name='Sheet1') 3 #excel.drop_duplicates(subset='name',inplace=True,keep='last') #keep默认为Firs 阅读全文
posted @ 2020-06-13 11:32 马蹄哒哒 阅读(200) 评论(0) 推荐(0)
摘要:1 import pandas 2 excel=pandas.read_excel(r'F:\pandas练习\成绩.xlsx',index_col='id',sheet_name='Sheet1') 3 temp=excel[['score1','score2']] 4 5 row_sum=tem 阅读全文
posted @ 2020-06-12 13:43 马蹄哒哒 阅读(230) 评论(0) 推荐(0)
摘要:1 import pandas 2 excel=pandas.read_excel('name.xlsx') 3 4 #这里的n是指保留前几列,默认为0或者1,意思是全部保留,expand指是否扩展,默认为False 5 d=excel['name'].str.split(n=0,expand=Tr 阅读全文
posted @ 2020-06-12 12:19 马蹄哒哒 阅读(352) 评论(0) 推荐(0)
摘要:1 import pandas 2 3 #定义数据效验函数 4 def score_validation(row): 5 try: 6 assert 0<=row['score']<=100 7 except: 8 print(row['sid'],row['name'],row['score']) 阅读全文
posted @ 2020-06-12 12:18 马蹄哒哒 阅读(162) 评论(0) 推荐(0)
摘要:(一)merge 1 merge(left, right, how='inner', on=None, left_on=None, right_on=None, 2 left_index=False, right_index=False, sort=True, 3 suffixes=('_x', ' 阅读全文
posted @ 2020-06-11 21:24 马蹄哒哒 阅读(407) 评论(0) 推荐(0)