Add a key to the column
I want to put a COUNTRY key in cars, but I can't.
The call should give the same result: a column COUNTRY should be added to cars
# Import cars data import pandas as pd cars = pd.read_csv ('cars.csv', index_col = 0) # Use .apply (str.upper) cars ["name_length"] = cars ["country"]. apply (str.upper) print (cars)
Did you correctly define the variable cars? There is no key 'COUNTRY'.
Answer # 1
If you want to put the key
cars, you need to set
cars ["COUNTRY"] =So
cars ["COUNTRY"] = cars ["country"]. Apply (str.upper)will work.
In the above code, key is specified as
By the way, it is an error statement, but I don't think this is an error in Python itself.
In the above code, the column name
countryvalue capitalized is inserted into
cars, and an error occurs. There should be no.
- python 3x - how to add a two-dimensional array
- python 3x - i want to get a matrix with the values of a certain column removed for each row of the matrix with pytorch (speedu
- python - read_excel specified range column cannot be read
- how to specify a column from one csv file in python and read it as list type or dict type
- python - i want to add a line number to the data frame
- python 3x - python i want to add the last weekday of the month as a new column to the data frame
- python hdf5 how to add to saved data (how to use mode ='a')
- python 3x - how to extract row and column numbers with specific values in a dataframe table
- python - i want to add an element to a double list
- python - updating a specific column in each row does not work in the case of duplicate index in dataframe
- python - apply format other than x column in pandas
- python - unable to sort by dropdown selection column in jquery datatables
- python - i want to insert a row name in the first column in sql
- python - add a line to the pandas dataframe
- python - i want to modify the value of a specific column or row of pandas using the apply function and the lambda function
- python - i want to set a value in a column that has no value by scraping the table and output it as csv
- python - i get a key error
- python - if the column that is pandas is other than the specified string, i want to rewrite the string in another column
- python - i want to search the value of the first column from two two-dimensional arrays with numpy, extract the row if the colum
- python key error