摘要:
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv', chunksize=50) df2 = pd.DataFrame() for chunk in df: df 阅读全文
摘要:
现有Series如下 np_array = np.random.randint(1, 10, 35) 要求转化为7行5列的DataFrame如下图: 解决办法: ser = pd.Series(np_array) df = pd.DataFrame(ser.values.reshape(7,5)) 阅读全文
摘要:
求两个Series的相关性 现有两个Series如下: import pandas as pd s1 = pd.Series([.2, .0, .6, .2]) s2 = pd.Series([.3, .6, .0, .1]) 求两个Series的皮尔逊系数 解决方法就是把Series当成是一个向量 阅读全文
摘要:
按照指定要求前向填充元素(ffill forward fill) 构建数据如下: import pandas as pd df=pd.DataFrame({"A":[5,3,None,4], "B":[None,2,4,3], "C":[4,3,8,5], "D":[5,4,2,None]}) df 阅读全文
摘要:
恢复内容开始 从Series的字符串中过滤出email地址 现有Series如下: emails = pd.Series(['buying books at amazom.com', 'rameses@egypt.com', 'matt@t.co', 'narendra@modi.com']) 解决 阅读全文
摘要:
恢复内容开始 计算两个Series之间的均方误差 现有两个Series如下: truth = pd.Series(range(10)) pred = pd.Series(range(10)) + np.random.random(10) 计算两个Series之间的均方误差解决办法: np.mean( 阅读全文
摘要:
11 把数据进行cut操作 现有数据ages如下 ages = [20, 22, 25, 27, 21, 23, 37, 31, 61, 45, 41, 32, 101] 想按照[(18, 25] < (25, 35] < (35, 60] < (60, 100]]把该数据进行Categories 阅读全文
摘要:
6 取出Series 1中独有的数据 现有两个Series, ser1和ser2 如下 ser1 = pd.Series([1, 2, 3, 4, 5]) ser2 = pd.Series([4, 5, 6, 7, 8]) 取出在ser1中出现,但不在ser2中出现的1,2,3出来 解决方法: se 阅读全文
摘要:
1 查看pandas的版本 import numpy as np import pandas as pd print(pd.__version__) 0.24.1 2 如何通过list,numpy array, dict创建series 现有list, numpy array, dict如下: im 阅读全文