Skip to main content
added 20 characters in body
Source Link
buran
  • 14.4k
  • 13
  • 45
  • 76

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

Updated: I see that the error is a "key error" however a key named "Name" should exist as it does when I run:

print(df.columns)

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')

print(df.columns) 

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

Updated: I see that the error is a "key error" however a key named "Name" should exist as it does when I run:

print(df.columns)

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

Updated: I see that the error is a "key error" however a key named "Name" should exist as it does when I run:

print(df.columns) 

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')
added 262 characters in body
Source Link

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

Updated: I see that the error is a "key error" however a key named "Name" should exist as it does when I run:

print(df.columns)

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

Updated: I see that the error is a "key error" however a key named "Name" should exist as it does when I run:

print(df.columns)

with output:

Index(['#,Name,Type 1,Type 2,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary'], dtype='object')

added 23 characters in body
Source Link
buran
  • 14.4k
  • 13
  • 45
  • 76

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

ErrorsErrors

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

I am trying to print a single column name and the corresponding values for that column in Python from a CSV file using pandas. I am able to print the column names, but when I then try to print just one of the columns with the following code:

import pandas as pd

df = pd.read_csv('pokemon_data.csv')

print(df['name'])

I then get these errors:

Errors

added 109 characters in body
Source Link
Loading
added 15 characters in body
Source Link
Loading
Source Link
Loading