粘贴答案不是目的
把Python学会这才叫做意义
童年的纸飞机
现在终于飞回我手里~~
这是网站给的答案,不过运行报错,其他关卡应该没问题。
def return_values():
import pandas as pd
L1 = [1,-2,2.3,'hq']
L2 = ['kl','ht','as','km']
T1 = (1,8,8,9)
T2 = (2,4,7,'hp')
data = {'a':L1,'b':L2,'c':T1,'d':T2}
A= pd.DataFrame(data)
t1 = pd.Series(L1,index = ['a','b','c','d'])
t2 = pd.Series(L2,index = ['a','b','c','d'])
t3 = pd.Series(T1,index = ['a','b','c','d'])
t4 = pd.Series(T2,index = ['a','b','c','d'])
t = {'L1':t1,'L2':t2,'T1':t3,'T2':t4}
B = pd.DataFrame(t)
return(A,B)
def return_values():
import pandas as pd
df1 = pd.read_excel('一、车次上车人数统计表.xlsx')
df2 = pd.read_table('txt1.txt',header=None)
reader = pd.read_csv('data.csv',chunksize=20000)
k=0;
names = locals()
for i in reader:
k=k+1
names['A%s'%k]=pd.DataFrame(i)
print('第'+str(k)+'次读取数据规模为: ',len(i))
print(i.shape)
def return_values():
import pandas as pd
A=pd.read_excel('Data.xlsx')
code=list(A['站点编号'].unique())
B=A.groupby(['站点编号','日期'])['进站人数','出站人数'].sum()
c=list(B.index)
A1=[]
A2=[]
for i in range(len(c)):
r=c[i]
A1.append(r[0])
A2.append(r[1])
sat_num=pd.DataFrame({'A1_站点编号':A1,'A2_日期':A2,'A3_进站人数':B['进站人数'].values,
'A4_出站人数':B['出站人数'].values})
D=sat_num.iloc[sat_num['A2_日期'].values'2015-10-07',:]
D1=D.groupby(['A1_站点编号'])['A3_进站人数','A4_出站人数'].sum()
sat_num2=pd.DataFrame({'A1_站点编号':list(D1.index),
'A2_进站人数':D1['A3_进站人数'].values,'A3_出站人数':D1['A4_出站人数'].values})
return(code,sat_num,sat_num2)
def return_values():
import pandas as pd
dict1={'code':['A01','A01','A01','A02','A02','A02','A03','A03'],
'month':['01','02','03','01','02','03','01','02'],
'price':[10,12,13,15,17,20,10,9]}
dict2={'code':['A01','A01','A01','A02','A02','A02'],
'month':['01','02','03','01','02','03'],
'vol':[10000,10110,20000,10002,12000,21000]}
dict1 = pd.DataFrame(dict1)
dict2 = pd.DataFrame(dict2)
df_inner=pd.merge(dict1,dict2,how='inner',on=['code','month'])
df_left=pd.merge(dict1,dict2,how='left',on=['code','month'])
df_right=pd.merge(dict1,dict2,how='right',on=['code','month'])
return(df_inner,df_left,df_right)
def return_values():
import pandas as pd
import numpy as np
dict1={'a':[2,2,'kt',6],'b':[4,6,7,8],'c':[6,5,np.nan,6]}
dict2={'d':[8,9,10,11],'e':['p',16,10,8]}
dict3={'a':[1,2],'b':[2,3],'c':[3,4],'d':[4,5],'e':[5,6]}
df1 = pd.DataFrame(dict1)
df2 = pd.DataFrame(dict2)
df3 = pd.DataFrame(dict3)
df4 = pd.concat([df1,df2],axis=1)
df5 = pd.concat([df3,df4],axis=0)
return(df4,df5)
def return_values():
import pandas as pd
L=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
S = pd.Series(L)
Sum = S.rolling(10).sum()
mean = S.rolling(10).mean()
max1 = S.rolling(10).max()
min1 = S.rolling(10).min()
return(L,S,Sum)
def return_values():
import pandas as pd
read = pd.read_excel('Data.xlsx')
zhandian = read.iloc[read['站点编号'].values==135,:]
riqi = zhandian.iloc[zhandian['日期'].values<'2015-10-03',:]
shike = riqi.iloc[riqi['时刻'].values>=9,:]
shike1 = shike.iloc[shike['时刻'].values11,:]
A1 = read['站点编号'].values==135
A2 = read['日期'].values<'2015-10-03'
A3 = read['时刻'].values>=9
A4 = read['时刻'].values11
A = read.iloc[A1&A2&A3&A4,[0,1,2,3]]
read = pd.read_excel('Data.xlsx')
zhandian = read.loc[read['站点编号'].values==135,:]
riqi = zhandian.loc[zhandian['日期'].values<'2015-10-03',:]
shike = riqi.loc[riqi['时刻'].values>=9,:]
shike1 = shike.loc[shike['时刻'].values11,:]
A1 = read['站点编号'].values==135
A2 = read['日期'].values<'2015-10-03'
A3 = read['时刻'].values>=9
A4 = read['时刻'].values11
B = read.loc[A1&A2&A3&A4,:]
return(A,B)
def return_values():
import pandas as pd
read = pd.read_excel('data.xlsx')
data = read.iloc[read['代码'].values=='600000.SH',:].sort_values('交易日期',axis=0)
da2 = read.sort_values(['代码','交易日期'])
return(data,da2)
def return_values():
import pandas as pd
import numpy as np
df = pd.read_excel('Data.xlsx')
df=df.iloc[df['日期'].values>='2015-10-08',:]
station = df.iloc[:,0].unique()
time = df.iloc[:,2].unique()
A1 =[]
A2 =[]
A3 =[]
A4 =[]
for i in range(len(station)):
d1=df.iloc[df['站点编号'].values==station[i],:]
for j in range(len(time)):
sk = d1['时刻'].unique()
if time[j] in sk:
jz_sum = d1.iloc[d1['时刻'].values==time[j],3].sum()
cz_sum = d1.iloc[d1['时刻'].values==time[j],4].sum()
A1.append(station[i])
A2.append(time[j])
A3.append(jz_sum)
A4.append(cz_sum)
df0=pd.DataFrame({'A1_站点编号':A1,'A2_时刻':A2,'A3_总进站客流':A3,'A4_总出站客流':A4})
df0.to_excel('各站点各时刻进出站客流数据.xlsx')
return(df0)
def return_values():
import random
import pandas as pd
code=list(range(1,31))
A=random.sample(code,30)
s=pd.Series(A,index=code)
return s
def return_values():
import random
import pandas as pd
t1=[]
t2=[]
t3=[]
t4=[]
t5=[]
for i in range(40):
t1.append(random.randint(1,70))
t2.append(random.randint(1,80))
t3.append(random.randint(1,50))
t4.append(random.randint(1,30))
t5.append(random.randint(1,20))
A=pd.DataFrame({'t1':t1,'t2':t2,'t3':t3,'t4':t4,'t5':t5})
return A
Original: https://blog.csdn.net/weixin_46322367/article/details/123986568
Author: 数据攻城小狮子
Title: 头歌Python数据框、序列定义及数据处理应用实验闯关
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/674196/
转载文章受原作者版权保护。转载请注明原作者出处!