Pandas adds a column so that the data content is divided by the other two columns

CSDN Q & A 2022-05-14 15:46:37 阅读数:895

pandasaddscolumndatacontent

Add a column of data The data content is the other two columns See step 11 for details ( I keep reporting errors after operation I hope someone can tell me in detail that I don't know much about this )

img




Take the answer :
import pandas as pddf = pd.DataFrame({
'tip': [9, 8, 7], 'total_bill': [3, 2, 1]})df['tip_ratio'] = df['tip'] / df['total_bill']""" The original data tip total_bill0 9 31 8 22 7 1 The effect is as follows tip total_bill tip_ratio0 9 3 3.01 8 2 4.02 7 1 7.0"""

版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/134/202205072343190315.html