'How to add columns to a dataframe without cutting off first row entry
Suppose I have a csv file which looks like this:
Alice,23
Bob,45
Chuck,9
Daren,25
Elisa,16
When I read it using pandas with:
df = pd.read_csv('my_csv.csv')
It becomes a dataframe that looks like this:
Alice 23
0 Bob 45
1 Chuck 9
2 Daren 25
3 Elisa 16
Then, when I want to rename the columns, i.e.
df.columns = ['name', 'age']
I get this:
name age
0 Bob 45
1 Chuck 9
2 Daren 25
3 Elisa 16
And as such, Alice of 23 years old is nowhere to be seen. What's the cleanest way to solve this issue? How to preserve the first data entry? Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
