-1

I'm concatenating three tuples from a csv but i´m thinking if there is any way to do it with a maximum lenght. I´m doing this:

df = pd.read_csv(FILE_NAME, header = 0)
df['all'] = df['Header'] + df['Subtitle'] + df['Text']

I want df['all] to be at most 500 characters

Thank you in advice

code12345
  • 13
  • 3

2 Answers2

0

You can slice the concatenation:

df['all'] = (df['Header'] + df['Subtitle'] + df['Text']).str[:500]
mozway
  • 194,879
  • 13
  • 39
  • 75
0

You can use the df.head() function to get the first rows of a dataframe:

df = pd.read_csv(FILE_NAME, header = 0)
df_short = df.head(500)
df_short['all'] = df_short['Header'] + df_short['Subtitle'] + df_short['Text']
OuterSoda
  • 175
  • 8