1

I have a csv file.

index  value    d F
0    975  25.35   5
1    976  26.28   4
2    977  26.24   1
3    978  25.76   0
4    979  26.08   0

I created a dataframe from CSV file this way. df = pd.read_csv("ThisFileL.csv")

I want to reconstruct a new DataFrame in my way by coppying the 2nd Columns three times.

data = pd.DataFrame()
data.add(df.value)
data.add(df.value)
data.add(df.value)

But it didn't work out. How can I do that?

2
  • 2
    Why do you want to do this? Commented Mar 14, 2014 at 2:55
  • Your file content is not separated by ,? Commented Mar 14, 2014 at 2:55

3 Answers 3

3

Have you tried data['value1']=data['value'], data['value2']=data['value'], etc? It should create new columns holding the numbers in value.

Sign up to request clarification or add additional context in comments.

Comments

2

You can do it by assigning 'value' column data in to new columns of the DataFrame.

df = pd.read_csv("ThisFileL.csv" , sep=' ')
df['value1'] = df.value
df['value2'] = df.value

The output of this would have following column headings.

index | value | d | F | value1 | value2

Comments

1

Creating a new column in a DataFrame is pretty straightforward. df[column_label] = values

What you're going to have to do is come up with some good names for your columns. I'll use a, b and c in this example.

df = pd.read_csv("ThisFileL.csv")
new_df = pd.DataFrame()
for key in ('a', 'b', 'c'):
    new_df[key] = df['value']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.