[英]How to set limit to python dataframe column length?
Can I set the limit of a column's value char legnth in py dataframe?我可以在 py dataframe 中设置列值字符长度的限制吗?
For example, in my CSV there are few columns which char value is more than 255 but I need to trim everything which is more than 255 characters.例如,在我的 CSV 中,char 值超过 255 的列很少,但我需要修剪超过 255 个字符的所有内容。 As the CSV is huge so I cannot do it in excel.由于 CSV 很大,所以我不能在 excel 中做到这一点。
I tried the below:我尝试了以下方法:
import pandas as pd
df1 = pd.read_csv (r'C:\Users\file.csv')
print (df1)
You can trim the length of a given column
to its first 255 characters with the following line:您可以使用以下行将给定column
的长度修剪为其前 255 个字符:
df1[column] = df1[column].str[:255]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.