熊猫 - 以系列和延迟操作

时间:2017-12-19 10:51:54

标签: python python-3.x pandas

我在Pandas中有以下数据框。我怀疑的是如何在有时间延迟的系列中进行操作。例如,我想计算将一个时期的GDP除以下一个时期的人口的结果。

         GDP     Population
1950     3.31        1
1951     3.5         1
...
2000     15.2        2

2 个答案:

答案 0 :(得分:3)

要做到这一点,你可以使用:

df['new_col'] = df['GDP'] / df['Population'].shift(1)

答案 1 :(得分:3)

您是否考虑过使用<?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" scope="COMPILE" name="Maven: com.google.guava:guava:18.0" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> </component> </module>

shift