简体   繁体   English

我是python的新手,我想使用python计算excel中列的字符串

[英]I am new to python and i want to calculate the string of the column in excel using python

I have attached a screen shot of my excel.我附上了我的excel的屏幕截图。 I want to calculate the length of every in Salary column.我想计算 Salary 列中每个的长度。 [I want salary length to be printed next to the salary column of each tring. [我想在每个 tring 的工资列旁边打印工资长度。

I am using following code but not able to print the data我正在使用以下代码但无法打印数据

import pandas as pd


# reading csv file
data = pd.read_csv("C:/Users/Desktop/python work/nba.csv")

# dropping null value columns to avoid errors
data.dropna(inplace = True)

# converting to string dtype
data["Salary"]= data["Salary"].astype(str)

# passing values
data["Salary Length"]= data["Salary"].str.len()

# converting back to float dtype
data["Salary"]= data["Salary"].astype(float)

# display
data][1]

在此处输入图片说明

You need to save the dataframe as a csv.您需要将数据框保存为 csv。 You can use: data.to_csv("C:/Users/Desktop/python work/nba_with_salary_length.csv")您可以使用: data.to_csv("C:/Users/Desktop/python work/nba_with_salary_length.csv")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想将特定列保存到 python 中的新 excel 表中 - i want to save a particular column into a new excel sheet in python 我在 Python Tkinter 中使用了一种新字体 - I am using a new Font in Python Tkinter 我想在python Excel中使用字符串“,”设置单元格。 但是excel很糟糕 - i want to set cell using string “,” in python excel. but excel is terrible 我想用下一行字更改“未命名”列的列名。 我对 python 有点陌生 - I want to change the column names of 'unnamed' columns with the immediate next line word. I am kinda new to python 我正在使用Python3,我想使用RabbitMQ - I am using Python3 and I want to use RabbitMQ 我想以python中的字典的形式显示Excel的一列 - I want to display a column of Excel in the form of a dictionary in python 我想知道如何使用 PYTHON 删除 excel 中单个列上的重复项 - I want to know how to Remove duplicates on a single column in excel USING PYTHON 我在使用 Python 脚本时遇到错误,该脚本旨在根据列类别拆分 Excel - I am getting error in using the Python script which is designed to split Excel based on column categories 正在使用 Python Django,我想验证一个 NVarchar 变量 - Am using Python Django and I want to validate a NVarchar variable 我想使用类和数据结构创建一个简单的库存管理系统。 我是 python 中 OOP 的新手 - I want to create a simple inventory management system using classes and data structures. I am new to OOP in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM